如何以全文宽度居中 LaTeX xtable 输出
How to center LaTeX xtable output in full text width
我正在使用 tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) 在乳胶中创建一个小报告。我有一个文件 code.Rnw,我编织成 code.tex。下面是我的 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 输出 (Table 1) 在全文中居中。默认情况下,在 tufte-handout 包中,它似乎将 table 居中在左侧非边距中。
我参考了几个来源,包括本期文章第一句中指出的来源 post。根据该参考资料,"Full page–width figures and tables may be placed in figure* or table* environments."我不确定如何完成此操作,因为我也在编写这份报告。
您可以通过将 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}
我正在使用 tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) 在乳胶中创建一个小报告。我有一个文件 code.Rnw,我编织成 code.tex。下面是我的 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 输出 (Table 1) 在全文中居中。默认情况下,在 tufte-handout 包中,它似乎将 table 居中在左侧非边距中。
我参考了几个来源,包括本期文章第一句中指出的来源 post。根据该参考资料,"Full page–width figures and tables may be placed in figure* or table* environments."我不确定如何完成此操作,因为我也在编写这份报告。
您可以通过将 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}