将 xtable 与 longtable 选项一起使用时重复标头
在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了实现此目的,您需要使用
print
函数的add.to.row
选项(运行?print.xtable
了解更多信息)。试试这个(改编自 R-Forge 上的一篇文章)
这是一个有点笨拙的解决方案,但至少它会为您提供大量的自定义功能。
In order to accomplish this, you'll need to use the
add.to.row
option of theprint
function (run?print.xtable
for more information).Try this (adapted from a post on R-Forge)
It's a bit clumsy of a solution, but at least it'll provide you with plenty of customization.
查看 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"
arefloating=TRUE
It does not emit the code specific for repeating the headers on subsequent pages. Check out
latex
in theHmisc
package. I know it has support for longtables as well, but I don't recall if it repeats headers correctly.