首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用带有longtable选项的xtable时重复标题

使用带有longtable选项的xtable时重复标题
EN

Stack Overflow用户
提问于 2011-09-17 04:38:01
回答 2查看 9.9K关注 0票数 11

在生成带有longtable选项的xtable时,有没有办法重复最上面的行/集合标题?

例如,如果我有

代码语言:javascript
复制
tableSb <- xtable(df, caption="A Very Long Table", label="ALongTable")
print(tableSb, include.rownames=TRUE, tabular.environment="longtable", floating=FALSE)

这可以很好地工作,但是当表格滚动到新页面时,标题不会重复。有什么建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-19 23:42:28

为了实现这一点,您需要使用print函数的add.to.row选项(运行?print.xtable可以获得更多信息)。

试试这个(改编自a post on R-Forge)

代码语言:javascript
复制
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

这是一个有点笨拙的解决方案,但至少它将为您提供大量的定制。

票数 26
EN

Stack Overflow用户

发布于 2011-09-17 04:50:55

看一下print.xtable的代码,当使用tabular.environment="longtable"时,它唯一要考虑的因素是

如果您还将标题设置在长表(顶部或底部)的正确位置,

  • 将发出警告

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7450141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档