如何在多个列上拆分?

时间:2022-01-12 23:16:45

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:

我正在尝试为使用RMarkdown的长表创建一个“纵向”布局。例如,我希望将一个表分成两列,如下面的示例所示:

dd <- data.frame(state=state.abb, freq=1:50)
kable(list(state=dd[1:25,], state=dd[26:50,]))

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?

但是,这种方法产生的输出看起来比正常的可输出的输出要差(例如,头不是粗体的)。是否有一种“合适”的方法来使用“可以”?

1 个解决方案

#1


2  

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.

kable是一个伟大的工具,但是有一定的局限性。对于您所描述的表类型,我将根据需要的输出使用两种不同的工具之一。

  • Hmisc::latex for .Rnw -> .tex -> .pdf

    Hmisc::乳胶的。rnw -> .tex -> .pdf。

  • htmlTable::htmlTable for .Rmd -> .md -> .html

    htmlTable: htmlTable for .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)

如何在多个列上拆分?

#1


2  

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.

kable是一个伟大的工具,但是有一定的局限性。对于您所描述的表类型,我将根据需要的输出使用两种不同的工具之一。

  • Hmisc::latex for .Rnw -> .tex -> .pdf

    Hmisc::乳胶的。rnw -> .tex -> .pdf。

  • htmlTable::htmlTable for .Rmd -> .md -> .html

    htmlTable: htmlTable for .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)

如何在多个列上拆分?