如何以完整的文本宽度居中放置LaTeX xtable输出 [英] How to center LaTeX xtable output in full text width

查看:228
本文介绍了如何以完整的文本宽度居中放置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}

\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程序包中,表格似乎在左侧非空白处居中.

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.

\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}

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

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