KableExtra - collapse_rows 对齐
KableExtra - collapse_rows alignment
我将以下代码放入我的 R Markdown 文档中,它根据我的数据框结构很好地折叠了行。如您所见,有一个水平对齐数据的 align
参数。是否有类似的 align_vertical
参数允许我垂直对齐?特别是我希望下面输出的 "a" 和 "b" 是 垂直顶部对齐的 。目前它们垂直居中对齐。
library(kableExtra)
library(knitr)
collapse_rows_dt <- data.frame(C1 = c(rep("a", 10), rep("b", 5)),
C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
C3 = 1:15,
C4 = sample(c(0,1), 15, replace = TRUE))
kable(collapse_rows_dt, "html", align = "c") %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T) %>%
collapse_rows(columns = 1:2)
如果你改变命令的顺序(最后执行column_spec
) you can use
extra_cssto change the
vertical-align` 属性:
library(kableExtra)
library(knitr)
collapse_rows_dt <- data.frame(C1 = c(rep("a", 10), rep("b", 5)),
C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
C3 = 1:15,
C4 = sample(c(0,1), 15, replace = TRUE))
kable(collapse_rows_dt, "html", align = "c") %>%
kable_styling(full_width = F) %>%
collapse_rows(columns = 1:2) %>%
column_spec(1, bold = T, extra_css = 'vertical-align: top !important;')
我将以下代码放入我的 R Markdown 文档中,它根据我的数据框结构很好地折叠了行。如您所见,有一个水平对齐数据的 align
参数。是否有类似的 align_vertical
参数允许我垂直对齐?特别是我希望下面输出的 "a" 和 "b" 是 垂直顶部对齐的 。目前它们垂直居中对齐。
library(kableExtra)
library(knitr)
collapse_rows_dt <- data.frame(C1 = c(rep("a", 10), rep("b", 5)),
C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
C3 = 1:15,
C4 = sample(c(0,1), 15, replace = TRUE))
kable(collapse_rows_dt, "html", align = "c") %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T) %>%
collapse_rows(columns = 1:2)
如果你改变命令的顺序(最后执行column_spec
) you can use
extra_cssto change the
vertical-align` 属性:
library(kableExtra)
library(knitr)
collapse_rows_dt <- data.frame(C1 = c(rep("a", 10), rep("b", 5)),
C2 = c(rep("c", 7), rep("d", 3), rep("c", 2), rep("d", 3)),
C3 = 1:15,
C4 = sample(c(0,1), 15, replace = TRUE))
kable(collapse_rows_dt, "html", align = "c") %>%
kable_styling(full_width = F) %>%
collapse_rows(columns = 1:2) %>%
column_spec(1, bold = T, extra_css = 'vertical-align: top !important;')