在生成带有longtable选项的xtable时,有没有办法重复最上面的行/集合标题?
例如,如果我有
tableSb <- xtable(df, caption="A Very Long Table", label="ALongTable")
print(tableSb, include.rownames=TRUE, tabular.environment="longtable", floating=FALSE)这可以很好地工作,但是当表格滚动到新页面时,标题不会重复。有什么建议吗?
发布于 2012-02-19 23:42:28
为了实现这一点,您需要使用print函数的add.to.row选项(运行?print.xtable可以获得更多信息)。
试试这个(改编自a post on R-Forge)
addtorow <- list()
addtorow$pos <- list()
addtorow$pos[[1]] <- c(0)
addtorow$command <- c(paste(
"\\hline \n",
"\\endhead \n",
"\\hline \n",
"{\\footnotesize Continued on next page} \n",
"\\endfoot \n",
"\\endlastfoot \n",
sep=""))
x.big <- xtable(
x,
label = "tabbig",
caption = "Example of longtable spanning several pages")
print(
x.big,
tabular.environment = "longtable",
floating = FALSE,
include.rownames = FALSE, # because addtorow will substitute the default row names
add.to.row = addtorow, # this is where you actually make the substitution
hline.after=c(-1)) # because addtorow will substitute the default hline for the first row这是一个有点笨拙的解决方案,但至少它将为您提供大量的定制。
发布于 2011-09-17 04:50:55
看一下print.xtable的代码,当使用tabular.environment="longtable"时,它唯一要考虑的因素是
如果您还将标题设置在长表(顶部或底部)的正确位置,
它不会发出特定于在后续页面上重复标题的代码。查看Hmisc包中的latex。我知道它也支持长表,但我不记得它是否正确地重复了标题。
https://stackoverflow.com/questions/7450141
复制相似问题