使用带有 longtable 选项的 xtable 时重复标题 [英] Repeat headers when using xtable with longtable option

查看:17
本文介绍了使用带有 longtable 选项的 xtable 时重复标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在生成带有 longtable 选项的 xtable 时,有没有办法重复顶行/设置标题?

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 选项/code> 函数(运行 ?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).

试试这个(改编自 R-Forge 上的帖子)

addtorow          <- list()
addtorow$pos      <- list()
addtorow$pos[[1]] <- c(0)
addtorow$command  <- c(paste(
  "\hline 
",
  "\endhead 
",
  "\hline 
",
  "{\footnotesize Continued on next page} 
",
  "\endfoot 
",
  "\endlastfoot 
",
  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.

这篇关于使用带有 longtable 选项的 xtable 时重复标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆