将xtable输出拆分为子表

时间:2011-09-14 21:52:02

标签: r sweave

当有多个列时,对使用带有Sweave的xtable有疑问。我正在处理的表有大约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生成解决方案,无法对单个文件进行更改。

提前致谢,

此致

  • 拉吉。

1 个答案:

答案 0 :(得分:3)

以下是?latex.table.by包中taRifx的示例。你可以使用LaTeX中的longtable来酿造类似的东西,并使用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

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

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

在标题中:

\usepackage{lscape}

围着你的桌子:

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

或者只使用sidewaystable

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