如何以全文宽度居中 LaTeX xtable 输出 [英] How to center LaTeX xtable output in full text width

查看:17
本文介绍了如何以全文宽度居中 LaTeX xtable 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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}

这会产生以下输出:

我想要做的是让 xtable 输出(表 1)在全文中居中.默认情况下,在 tufte-handout 包中,它似乎在左侧非边距中居中.

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.

推荐答案

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

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}

这篇关于如何以全文宽度居中 LaTeX xtable 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆