Search code examples
rgt

gt() table - header color


How do I add color to the header (i.e the column names) of my data frame using the gt() function in R

gt_Head <-
  gt_Head %>%
  tab_header(
  title = md("**Table of First 10 Observations**")
  )%>%
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_body(
      rows = 0  
    )
  )

Solution

  • You can use the column_labels.background.color option (see all options here), e.g.

    library(gt)
    head(mtcars, 10) |> 
      gt() |> 
      tab_header(
        title = md("**Table of First 10 Observations**")
      ) |> 
      tab_options(column_labels.background.color = "blue")
    

    enter image description here