问题描述
在生成带有longtable选项的xtable时,是否可以重复顶部行/set标头?
Is there a way to repeat the top row / set headers when generating an xtable with a longtable option ?
例如,如果我有
tableSb <- xtable(df, caption="A Very Long Table", label="ALongTable")
print(tableSb, include.rownames=TRUE, tabular.environment="longtable", floating=FALSE)
这很好,但是当表翻转到新页面时,标题将不会重复.有什么建议吗?
This works fine, but when the tables roll over into a new page the headers are not repeated. Any suggestions ?
推荐答案
为此,您需要使用print
函数的add.to.row
选项(有关更多信息,请运行?print.xtable
).
In order to accomplish this, you'll need to use the add.to.row
option of the print
function (run ?print.xtable
for more information).
尝试一下(改编自 https://r-forge.r-project.org/tracker/?func=detail&atid=4864&aid=1627&group_id=1228 )
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
解决方案有点笨拙,但至少它将为您提供大量自定义功能.
It's a bit clumsy of a solution, but at least it'll provide you with plenty of customization.
这篇关于将xtable与longtable选项一起使用时重复标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!