如何在多列上拆分kable? [英] How to split kable over multiple columns?

查看:66
本文介绍了如何在多列上拆分kable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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屋!

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