<-
tab_1 |>
gtcars ::select(model, year, hp, trq) |>
dplyr::slice(1:5) |>
dplyrgt(rowname_col = "model") |>
tab_stubhead(label = "car")
The gtsave()
function
Using a small subset of the gtcars
dataset, we can create a gt table with row labels. We’ll add a stubhead label with the tab_stubhead()
function to describe what is in the stub.
Export the gt table to an HTML file with inlined CSS (which is necessary for including the table as part of an HTML email) using gtsave()
and the inline_css = TRUE
option.
|> gtsave(filename = "tab_1.html", inline_css = TRUE) tab_1
By leaving out the inline_css
option, we get a more conventional HTML file with embedded CSS styles.
|> gtsave(filename = "tab_1.html") tab_1
Saving as a PNG file results in a cropped image of an HTML table. The amount of whitespace can be set with the expand
option.
|> gtsave("tab_1.png", expand = 10) tab_1
Any use of the .tex
, .ltx
, or .rnw
will result in the output of a LaTeX document.
|> gtsave("tab_1.tex") tab_1
With the .rtf
extension, we’ll get an RTF document.
|> gtsave("tab_1.rtf") tab_1
With the .docx
extension, we’ll get a word/docx document.
|> gtsave("tab_1.docx") tab_1