rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.03k stars 209 forks source link

How to preserve font formatting for LaTeX output #937

Open PMassicotte opened 2 years ago

PMassicotte commented 2 years ago

Prework

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

image

LaTeX preview

image

Is it possible to keep font formatting in the LaTeX file?

cswingle commented 2 years ago

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.