使用R-studio和Knitr创建一个pdf我无法让这些表格以焦点为中心.从下面的例子可以看出,使用xtable()可以正常工作,但latex() - tabels都是左对齐的.据我了解Hmisc文档,从latex()创建的表应该是自动地进行水平居中,但我必须做错事.
\documentclass{article}
\begin{document}
<<>>=
library(Hmisc)
library(tables)
library(xtable)
@
The tables are all left-aligned:
<<results='asis'>>=
latex( tabular( (Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) )
@
<<results='asis'>>=
latex( tabular( (Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ),center="center" )
@
<<results='asis'>>=
latex( tabular( (Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ),center="centering" )
@
I have tried to use the fig.align option, but it does not do it:
<<results='asis',fig.align='center'>>=
latex( tabular( (Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) )
@
with xtable it automatically centers:
<<results='asis'>>=
xtable(table(Puromycin$conc, Puromycin$state))
@
\end{document}
Run Code Online (Sandbox Code Playgroud)
R版本3.0.0(2013-04-03)
平台:x86_64-w64-mingw32/x64(64位)
我没有时间去通过代码latex.s中的Hmisc包,但直到我做的,随意包装你的块到中心环境.不是最干净的解决方案,但它完成了工作.
\begin{centering}
<<results='asis'>>=
latex(tabular((Species + 1) ~ (n=1) + Format(digits=2)*(Sepal.Length + Sepal.Width)*(mean + sd), data=iris ))
@
\end{centering}
Run Code Online (Sandbox Code Playgroud)
这会产生一个居中的表格.