library(gtsummary)
<- gtsummary::tbl_summary(gtsummary::trial, by = trt, include = c(age, grade), missing = "always", label = list(age = "Age \n\U00A0\U00A0linebreak in a cell")) |> add_overall()
tbl <- tbl$table_body |>
gt_table ::gt(caption = gt::md("This is the caption \n[Used for cross referencing in Quarto]")) |>
gt::fmt_markdown(columns = label) |> # need this to recognize the line break in the table body
gt# Column headers with line breaks
::cols_label(
gtstat_0 = gt::md("**Overall**"),
stat_1 = gt::md("**Drug A** \nManual Line Break"),
stat_2 = gt::md("**Drug B** \nManual Line Break")
|>
) ::tab_header(gt::md("This is the Title \nwith a linebreak"), subtitle = "This is the Subtitle") gt
Line Breaks
Testing Line Breaks output
Line breaks not being rendered correctly in a PDF is a known issue. We will skip the quarto rendered PDF and evaluate the line break behavior in other output options.
The example table evaluates line breaks in: - Title - Column Headers - Table Header - Cells
gt_save PDF
::gtsave(gt_table, filename = "outputs/pdf/linebreaks_gt_pdf.pdf") gt
rmarkdown rendered PDF
gt_table
gt_save rendered word file
::gtsave(gt_table, filename = "outputs/docx/linebreaks_gt_word.docx") gt
quarto rendered word file
gt_table
rmarkdown rendered word file
gt_table