9

当有多个列时,对使用 xtable 和 Sweave 有疑问。我正在处理的表有大约 25 列和 5 行。不知道确切的列数,因为这是动态的。

当我跑的时候说,

表 1 <- 表 (df$someField)

我得到一个基本上超过页面长度的表格。

       ColA    ColB    ColC
---------------------------
RowA   1       2       3   ......
RowB   3       4       6   ......

如果对此做一个 xtable,并通过 Sweave 运行它,

xtable(table1, caption="some table")

它溢出了。

我正在寻找的是类似的东西,

       ColA    ColB    ColC
---------------------------
RowA   1       2       3 
RowB   3       4       6 

       ColD    ColE    ColF 
---------------------------
RowA   11       9       34 
RowB   36       8       65  

使用 \hline 等标记。基本上,将 xtable 拆分为每个“子表”5 列。

我也在批处理作业中运行它,所以我将无法对单个文件进行更改,无论它必须能够通过在 Rnw 文件上运行 Sweave 来生成什么解决方案。

提前致谢,

问候,

  • 拉吉。
4

1 回答 1

3

这是包中的一个?latex.table.by示例taRifxlongtable您可以在 LaTeX 中使用类似的东西来酿造类似的东西,并将latex.table.by代码用作原型。

my.test.df <- data.frame(grp=rep(c("A","B"),10),data=runif(20))
library(xtable)
latex.table.by(my.test.df)
#   print(latex.table.by(test.df), include.rownames = FALSE, include.colnames = TRUE, sanitize.text.function = force)
#   then add \usepackage{multirow} to the preamble of your LaTeX document
#   for longtable support, add ,tabular.environment='longtable' to the print command (plus add in ,floating=FALSE), then \usepackage{longtable} to the LaTeX preamble

无论如何,longtableLaTeX 中的包是关键。

编辑:看来你有太多的列而不是太多的行。在这种情况下,首先尝试美化该页面。

在标题中:

\usepackage{lscape}

在你的桌子周围:

\begin{landscape}
...
\end{landscape}

或者只是使用sidewaystable.

如果您的表格太宽而无法放入一页,请尝试使用该supertabular包,从描述中听起来它可能会根据宽度处理多个页面(但我从未使用过它,因此无法确定)。

于 2011-09-14T22:53:46.267 回答