# \donttest{
# Create table with variable groups
my_tbl <- gtsummary::trial |>
gtsummary::tbl_summary(by = trt, include = c(age, marker, grade, stage)) |>
gtsummary::add_variable_group_header(
header = "Demographics",
variables = age
) |>
gtsummary::add_variable_group_header(
header = "Clinical",
variables = marker:stage
) |>
add_group_styling()
# Get group row numbers before conversion
group_rows <- get_group_rows(my_tbl)
# Convert to gt and apply gray background
my_tbl |>
gtsummary::as_gt() |>
gt::tab_style(
style = gt::cell_fill(color = "#E8E8E8"),
locations = gt::cells_body(rows = group_rows)
)
# }
Run the code above in your browser using DataLab