更改kableExtra表标题的字体大小 [英] Changing the font size of headers of kableExtra table

查看:67
本文介绍了更改kableExtra表标题的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改下表中各种标题的字体大小.

I am trying to change the font size of various headers in the following table.

library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:6]
kable(dt) %>%
kable_styling(c("striped", "bordered")) %>%
add_header_above(c(" ", "Group 1" = 2, "Group 2" = 2, "Group 3" = 2)) %>%
add_header_above(c(" ", "Group 4" = 4, "Group 5" = 2)) %>%
add_header_above(c(" ", "Group 6" = 6))

来自上面代码的表格图片:

但是,我希望标题组6远大于组4和5,而组1,2,3再次较小.这可能吗?

However, I would like the header group 6 to be far bigger than Group 4 and 5 and groups 1,2,3 to be smaller again. Is this possible?

除此之外,是否可以调用一个对象来命名"Group6"标题,而不必键入字符串?

In addition to this is it possible to call an object for titleing the "Group6" header rather than having to type the string?

先谢谢您,

推荐答案

  • 添加到表格顶部的最上面的分组行包括根据要求的动态标签;
  • 在表顶部添加的以下分组行使用手动设置的标签.
  • 他的帖子如何在@Rene中使用使用 add_header_above()对添加在表顶部的行进行分组.

    Credits to @Rene for his post how to use dynamic labeling for grouping rows added on top of the table with add_header_above().

    vec <- c("Properties A", "Properties B")
    mtcars[1:3,1:4] %>% kable() %>% 
      kable_styling() %>% 
      # 2nd. level of grouping rows: manual labels
      add_header_above(
        c(" " = 1, 
          "Features" = 2, 
          "Features" = 2), 
        font_size = 15) %>%
      # 1st. level of grouping rows: dynamic labels
      add_header_above(
        c(" " = 1, 
        setNames(2, vec[1]),
        setNames(2, vec[1])), 
        font_size = 25) 
    

    这篇关于更改kableExtra表标题的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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