How can I change style of row of groups in table gt

49 Views Asked by At

I would like to change to bold the titles of Consumer Non-Durables, Healthcare, Hitech, etc...

This is the code I am using

# Create a table using gt
table <- wide_summary_df %>%
  gt() %>%
  tab_header(
    title = "Summary Table",
    subtitle = "Total Acqprop by Year, Newname, and Decile"
  ) %>%
  cols_label(
    newname = "Newname",
    decile = "Deciles per sector"
  ) %>%
  fmt_percent(decimals = 1, columns = c("1985", "1990", "1995", "2001", "2008", "2020" ))%>%
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_body(
      columns = decile
    ))

# Print the table
table


# Print the table
table

This is the output so far: enter image description here

1

There are 1 best solutions below

2
On

You could add a line to bold that column with cells_body(1,). I tested this with another gt I had open but I didn't test your code.

table <- wide_summary_df %>%
  gt() %>%
  tab_header(
    title = "Summary Table",
    subtitle = "Total Acqprop by Year, Newname, and Decile"
  ) %>%
  cols_label(
    newname = "Newname",
    decile = "Deciles per sector"
  ) %>%
  fmt_percent(decimals = 1, columns = c("1985", "1990", "1995", "2001", "2008", "2020" ))%>%
  tab_style(
    style = cell_text(weight = "bold"),
    locations =  |> 
  tab_style(
    style = cell_text(color = "black", weight = "bold"),
    locations = list(cells_body(columns = decile),
      cells_body(1,)
      )
  )

Source: Location helper for targeting row groups