Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_latex

Output a gt object as LaTeX


Description

Get the LaTeX content from a gt_tbl object as a knit_asis object. This object contains the LaTeX code and attributes that serve as LaTeX dependencies (i.e., the LaTeX packages required for the table). Using as.character() on the created object will result in a single-element vector containing the LaTeX code.

Usage

as_latex(data)

Arguments

data

A table object that is created using the gt() function.

Function ID

13-3

See Also

Other Export Functions: as_raw_html(), as_rtf(), extract_summary(), gtsave()

Examples

# 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()

gt

Easily Create Presentation-Ready Display Tables

v0.2.2
MIT + file LICENSE
Authors
Richard Iannone [aut, cre] (<https://orcid.org/0000-0003-3925-190X>), Joe Cheng [aut], Barret Schloerke [aut] (<https://orcid.org/0000-0001-9986-114X>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.