首页 > 解决方案 > 如何在 r 中使用 gt 调整 column_labels 边框?

问题描述

我正在尝试用 gt() 制作一张桌子。只要我将 column_label.border.top/bottom.width 设置为 4(或更高) gt 就可以正常工作:

library(gt)

tab_1 <- exibble %>%
  select(-c(fctr, date, time, datetime)) %>%
  gt(
      rowname_col = "row",
      groupname_col = "group") %>%
    tab_header(
      title = md("Data listing from **exibble**"),
      subtitle = md("`exibble` is an R dataset")) %>% 
    tab_options(
      table.border.top.width = 0, 
      table.border.bottom.width = 0, 
      column_labels.border.top.width = 4, 
      column_labels.border.bottom.width = 8, 
      column_labels.border.top.color = "blue",
      column_labels.border.bottom.color = "green") 
  
tab_1 

结果:粗边框和蓝色/绿色

但是,一旦我做了完全相同的操作,但将 column_labels.border.top/bottom.width 设置为较低的值(例如 1),它就会恢复为默认宽度并且颜色会消失。

tab_2 <- exibble %>%
  select(-c(fctr, date, time, datetime)) %>%
  gt(
      rowname_col = "row",
      groupname_col = "group") %>%
    tab_header(
      title = md("Data listing from **exibble**"),
      subtitle = md("`exibble` is an R dataset")) %>% 
    tab_options(
      table.border.top.width = 0, 
      table.border.bottom.width = 0, 
      column_labels.border.top.width = 1, 
      column_labels.border.bottom.width = 1, 
      column_labels.border.top.color = "blue",
      column_labels.border.bottom.color = "green") 
  
tab_2 

结果:默认线宽,没有颜色

我究竟做错了什么?

标签: bordergt

解决方案


推荐阅读