当前位置 : 主页 > 网络推广 > seo >

位置 – 如何使LaTeX xtable输出以全文宽度居中

来源:互联网 收集:自由互联 发布时间:2021-06-16
我正在使用tufte-handout( http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf)在乳胶中创建一个小报告.我有一个文件代码.我编码为code.tex.下面是我的代码.Rnw: \documentclass[12
我正在使用tufte-handout( http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf)在乳胶中创建一个小报告.我有一个文件代码.我编码为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}

这产生以下输出:

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

我曾咨询过几个消息来源,其中包括本职位第一句中指出的内容.根据该参考,“全页宽数字和表可以放置在图*或表*环境中.我不确定如何完成这个,因为我也编织这份报告.

您可以通过将longtable包装在tffte全宽环境中来解决此问题.此解决方法似乎还需要一个小的hack(在第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}
网友评论