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

时间:2015-07-07 01:32:34

标签: position latex knitr xtable

我正在使用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}

这会产生以下输出:

this is my output

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

我咨询了几个来源,包括当前帖子第一句中指出的来源。根据该参考文献,&#34;可以在图*或表*环境中放置完整页宽图形和表格。&#34;鉴于我也正在编写​​这份报告,我不确定如何实现这一目标。

1 个答案:

答案 0 :(得分:4)

您可以通过将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}