The cells_stubhead() function

Using a summarized version of the pizzaplace dataset, let’s create a gt table. Add a stubhead label with tab_stubhead() and then style it with tab_style() in conjunction with the use of cells_stubhead() in the locations argument.

pizzaplace |>
  dplyr::mutate(month = as.numeric(substr(date, 6, 7))) |>
  dplyr::group_by(month, type) |>
  dplyr::summarize(sold = dplyr::n(), .groups = "drop") |>
  dplyr::filter(month %in% 1:2) |>
  gt(rowname_col = "type") |>
  tab_stubhead(label = "type") |>
  tab_style(
    style = cell_fill(color = "lightblue"),
    locations = cells_stubhead()
  )
type month sold
chicken 1 913
classic 1 1257
supreme 1 1044
veggie 1 1018
chicken 2 875
classic 2 1178
supreme 2 964
veggie 2 944