如何在多列上拆分kable? [英] How to split kable over multiple columns?
问题描述
我正在尝试使用kable
为RMarkdown中的长表生成纵向"布局.例如,我希望将表格分为两列,如以下示例所示:
I am trying to produce a "longitudinal" layout for long tables in RMarkdown with kable
. For example, I would like a table to be split over two columns, like in the example below:
dd <- data.frame(state=state.abb, freq=1:50)
kable(list(state=dd[1:25,], state=dd[26:50,]))
但是,此hack产生的输出看起来比正常的kable
输出差很多(例如,标头未使用粗体显示).是否有使用"kable
"执行此操作的适当"方法?
However, this hack produces an output that looks a way worse than the normal kable
output (for example the header is not in bold). Is there a "proper" way to do this using kable
?
推荐答案
kable
是一个很好的工具,但有其局限性.对于您要描述的表类型,我将根据所需的输出使用两种不同的工具之一.
kable
is a great tool, but has limits. For the type of table you're describing I would use one of two different tools depending on output wanted.
-
Hmisc::latex
表示.Rnw -> .tex -> .pdf
htmlTable::htmlTable
为.Rmd -> .md -> .html
以下是后者的一个示例:
Here is an example of the latter:
dd <- data.frame(state=state.name, freq=1:50)
dd2 <- cbind(dd[1:25, ], dd[26:50, ])
library(htmlTable)
htmlTable(dd2,
cgroup = c("Set 1:25", "Set 26:50"),
n.cgroup = c(2, 2),
rnames = FALSE)
这篇关于如何在多列上拆分kable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!