如何以全文宽度居中LaTeX xtable输出

12 latex position xtable knitr

我正在使用tufte-handout(http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf)在latex中创建一个小报告.我有一个文件代码.我编译成code.tex.下面是我的代码.Rnw:

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

\begin{document}

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

\centerline{\Large\bf 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. 
\bigskip{}

<<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}
Run Code Online (Sandbox Code Playgroud)

这会产生以下输出:

这是我的输出

我想要做的是允许xtable输出(表1)在整个文本中居中.默认情况下,在tufte-handout包中,它似乎将表放在左边的非边距中.

我咨询了几个来源,包括当前这篇文章第一句中所指出的来源.根据该参考文献,"整页宽度的数字和表格可以放在图*或表格*环境中." 我不确定如何实现这一点,因为我也编织了这份报告.

Chr*_*mer 5

您可以通过将其包装longtable在tufte fullwidth环境中来解决此问题.这种解决方法似乎也需要一个小的黑客(在第2行)来修复hsize,但它似乎按预期工作.

\begin{fullwidth}
\makeatletter\setlength\hsize{\@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}
Run Code Online (Sandbox Code Playgroud)