有一个关于在有多列时将 xtable 与 Sweave 结合使用的问题。我正在处理的表格大约有 25 列和 5 行。确切的列数未知,因为它是动态的。
当我运行时说,
table1 <- table (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 生成什么解决方案。
提前致谢,
问候,
- 拉吉。
最佳答案
以下是来自 taRifx
包中 ?latex.table.by
的示例。您可以在 LaTeX 中使用 longtable
编写类似的内容,并使用 latex.table.by
代码作为原型(prototype)。
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
无论如何,LaTeX 中的 longtable
包是关键。
编辑:看来您的列太多,而不是行太多。在这种情况下,首先尝试仅美化该页面。
在标题中:
\usepackage{lscape}
在你的 table 周围:
\begin{landscape}
...
\end{landscape}
或者只使用sidewaystable
。
如果您的表格太宽而无法容纳一页,请尝试 supertabular
包,从描述来看,它可能会根据宽度处理跨多个页面的情况(但我从未使用过)所以不能确定)。
关于r - 将 xtable 输出拆分为子表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7423423/