# NOT RUN {
# Use `gtcars` to create a gt table;
# add a header and then export as
# an object with LaTeX code
tab_latex <-
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")
) %>%
as_latex()
# `tab_latex` is a `knit_asis` object,
# which makes it easy to include in
# R Markdown documents that are knit to
# PDF; we can use `as.character()` to
# get just the LaTeX code as a single-
# element vector
tab_latex %>%
as.character() %>%
cat()
# }
Run the code above in your browser using DataLab