Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

position - How to center LaTeX xtable output in full text width

I am using tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) to create a small report in latex. I have a file code.Rnw that I knit into code.tex. Below is my code.Rnw:

documentclass[12pt,english,nohyper]{tufte-handout}
usepackage{longtable}
usepackage{geometry}

egin{document}

<<include=FALSE>>=
library(ggplot2)
library(xtable)
@

centerline{Largef This is my Main Title}

<<echo=FALSE,results='asis'>>=
fname='plot1.pdf'
pdf(fname,width=4,height=4)
print(qplot(mpg,cyl,data=mtcars))
{dev.off();invisible()}
cat(sprintf('\begin{marginfigure}
\includegraphics[width=0.98\linewidth]{%s}
\caption{\label{mar:hist}MPG vs CYL in MTCARS dataset.}
\end{marginfigure}',sub('\.pdf','',fname)))
@

This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report.

This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. 
igskip{}

<<echo=FALSE,results='asis'>>=
x.big <- xtable(mtcars[1:20,1:4], label ='tab:mtcars',caption ='This is the mtcar dataset head.',align = c("rr|lr|r"))

print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)
@

end{document}

This produces the following output:

this is my output

What I am trying to do is to allow the xtable output (Table 1) to be centered across the full text. By default, in the tufte-handout package, it seems to center the table in the left non-margin.

I have consulted several sources, including the one indicated in the first sentence of this current post. According to that reference, "Full page–width figures and tables may be placed in figure* or table* environments." I am unsure how to accomplish this, given that I am also knitting this report.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can work around this problem by wrapping the longtable in a tufte fullwidth environment. This workaround also seems to require a small hack (in line 2) to fix the hsize, but it appears to work as intended.

egin{fullwidth}
makeatlettersetlengthhsize{@tufte@fullwidth}makeatother
<<echo=FALSE,results='asis'>>=
x.big <- xtable(mtcars[1:20,1:4], label ='tab:mtcars',caption ='This is the mtcar dataset head.',align = c("rr|lr|r"))

print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)
@
end{fullwidth}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...