library(gtsummary)
<- gtsummary::tbl_summary(gtsummary::trial, by = trt, include = c(age, grade), missing = "always", label = list(age = "Age")) |> add_overall()
tbl
<- tbl$table_body |>
gt_table ::gt(caption = gt::md("This is the caption")) |>
gt::fmt_markdown(columns = label) |> # need this to recognize the line break in the table body
gt::cols_hide(columns = c(variable, var_type, row_type, var_label)) |>
gt::sub_missing(missing_text = "") |>
gt# spanning headers 1 and 2 levels
::tab_spanner(gt::md("**Spanning Level 2**"), columns = gtsummary::all_stat_cols(), level = 2L, id = "stat_1_L2") |>
gt::tab_spanner(gt::md("**Spanning Level 1**"), columns = gtsummary::all_stat_cols(FALSE), level = 1L, id = "stat_1_L1") |>
gt::tab_spanner(gt::md("**Both Treatments**"), columns = stat_0, level = 1L, id = "stat_0_L1") gt
Spanning Header
Testing Spanning Header output
gt_save PDF
::gtsave(gt_table, filename = "outputs/pdf/spanning_header_gt_pdf.pdf") gt
rmarkdown rendered PDF
gt_table
gt_save rendered word file
::gtsave(gt_table, filename = "outputs/docx/spanning_header_gt_word.docx") gt
quarto rendered word file
gt_table
rmarkdown rendered word file
gt_table