Search code examples
rgt

Partially bold colunm headers with gt


I want to use the R package gt and have the table output ONE and TWO in bold. It looks like you can use markdown syntax inside gt but this doesn't quite work as I'd expect. Any tips?

dummy <- tibble(
  `**ONE**, N = 1` = 1,
  `**TWO**, N = 2` = 2
)

dummy %>% 
  gt()

Solution

  • Couldn't see anyway to do exactly what you want but this accomplishes it by having a list that maps column names to label name with formatting.

    library(tibble)
    library(gt)
    dummy <- tibble(
    "one" = 1,
    "two" = 2
    )
    
    col_for_list <- list(one = md("**ONE**, N = 1"), two = md("**TWO**, N = 2"))
    
    dummy %>%
    gt::gt() %>%
    cols_label(.list = col_for_list)