gt
gt copied to clipboard
How to preserve font formatting for LaTeX output
Prework
- [X] Read and agree to the code of conduct and contributing guidelines.
- [X] For any problems you identify, a minimal reproducible example so the maintainer can troubleshoot. A reproducible example is:
- [X] Runnable: post enough R code and data so any onlooker can create the error on their own computer.
- [X] Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
- [X] Readable: format your code according to the tidyverse style guide.
Question
I tried to browse existing issues, sorry if this has been already answered.
I need to export a table, which contains different font size and weight, in latex. The HTML output looks perfect, but I am losing the formatting once exported into a LaTeX file.
Reproducible example
library(gt)
table <- mtcars |>
gt(groupname_col = c("cyl"), rowname_col = "gear") |>
tab_options(
row_group.font.weight = "bold",
row_group.font.size = px(14),
data_row.padding = px(1),
table.font.size = px(12),
column_labels.font.size = px(14),
column_labels.font.weight = "bold"
)
table |>
gtsave("~/Desktop/test.tex")
table |>
gtsave("~/Desktop/test.html")
Created on 2022-04-28 by the reprex package (v2.0.1)
HTML preview
LaTeX preview
Is it possible to keep font formatting in the LaTeX file?
Maybe this is obvious if you're more familiar with the code, but this issue is also true if you are producing a table in a document using quarto (the tab_options
are reflected in the HTML document, but not PDF), not just when using gtsave
.