Rmarkdown/knitr captions for tables using {gtsummary}

1.1k Views Asked by At

What is the best option or suggested workflow for adding captions to gtsummary tables in Rmarkdown documents?

For examples, I know there's a function for kable tables, so in theory one might convert one into the other using gtsummary::as_kable(), but somehow this doesn't feel optimal. Suggestions?

Thanks!

1

There are 1 best solutions below

3
On BEST ANSWER

The gt package has many many functions for controlling how a gt table prints. I suggest you convert the gtsummary object to gt using the as_gt() function, then continue customizing with gt functions. https://gt.rstudio.com/ Small example included below. enter image description here

library(gtsummary)

mod <- glm(response ~ age + grade, trial, family = binomial)

tbl_regression(mod, exponentiate = TRUE) %>% 
  as_gt() %>%
  gt::tab_header("Table 1. Very Informative Model",
                 subtitle = "Highly Confidential")

enter image description here