The rm_caption() function
Use gtcars to create a gt table. Add a header part with the tab_header() function, and, add a caption as well with tab_caption().
gt_tbl <-
gtcars |>
dplyr::select(mfr, model, msrp) |>
dplyr::slice(1:5) |>
gt() |>
tab_header(
title = md("Data listing from **gtcars**"),
subtitle = md("`gtcars` is an R dataset")
) |>
tab_caption(caption = md("**gt** table example."))
gt_tbl
gt table example.
| Data listing from gtcars |
gtcars is an R dataset |
| mfr |
model |
msrp |
| Ford |
GT |
447000 |
| Ferrari |
458 Speciale |
291744 |
| Ferrari |
458 Spider |
263553 |
| Ferrari |
458 Italia |
233509 |
| Ferrari |
488 GTB |
245400 |
If you decide that you don’t want the caption in the gt_tbl object, it can be removed with the rm_caption() function.
rm_caption(data = gt_tbl)
| Data listing from gtcars |
gtcars is an R dataset |
| mfr |
model |
msrp |
| Ford |
GT |
447000 |
| Ferrari |
458 Speciale |
291744 |
| Ferrari |
458 Spider |
263553 |
| Ferrari |
458 Italia |
233509 |
| Ferrari |
488 GTB |
245400 |