将 xtable 与 longtable 选项一起使用时重复标头

发布于 2024-12-05 01:45:13 字数 296 浏览 2 评论 0原文

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

例如,如果我有

tableSb <- xtable(df, caption="A Very Long Table", label="ALongTable")
print(tableSb, include.rownames=TRUE, tabular.environment="longtable", floating=FALSE)

这个工作正常,但是当表格滚动到新页面时,标题不会重复。有什么建议吗?

Is there a way to repeat the top row / set headers when generating an xtable with a longtable option ?

For eg., if I have

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拍不死你 2024-12-12 01:45:13

为了实现此目的,您需要使用 print 函数的 add.to.row 选项(运行 ?print.xtable了解更多信息)。

试试这个(改编自 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

这是一个有点笨拙的解决方案,但至少它会为您提供大量的自定义功能。

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).

Try this (adapted from 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

It's a bit clumsy of a solution, but at least it'll provide you with plenty of customization.

一指流沙 2024-12-12 01:45:13

查看 print.xtable 的代码,当 tabular.environment="longtable" 时,它唯一需要考虑的是

  • 如果您还设置了 floating=TRUE 则发出警告
  • 。在长表的正确位置(顶部或底部)

它不会发出特定于在后续页面上重复标题的代码。查看 Hmisc 包中的 latex。我知道它也支持长表,但我不记得它是否正确重复标题。

Looking at the code for print.xtable, the only considerations it makes when tabular.environment="longtable" are

  • Emitting a warning if you also set floating=TRUE
  • Putting the caption in the right place for a longtable (top or bottom)

It does not emit the code specific for repeating the headers on subsequent pages. Check out latex in the Hmisc package. I know it has support for longtables as well, but I don't recall if it repeats headers correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文