I cannot see how to add the color of the cells when I export a gt
table to LaTeX.
gt::exibble |>
dplyr::select(num) |>
gt::gt() |>
gt::tab_style(
style = gt::cell_fill(color = "lightcyan"),
locations = gt::cells_body(
columns = num,
rows = num >= 5000
)
) |>
gt::as_latex() |>
as.character()
The previous table should have some light blue cells, which are perfectly visible using the HTML rendering.
However, there is no color on the output LaTeX code:
\\begin{longtable}{r}\n\\toprule\nnum \\\\ \n\\midrule\n1.111e-01 \\\\ \n2.222e+00 \\\\ \n3.333e+01 \\\\ \n4.444e+02 \\\\ \n5.550e+03 \\\\ \nNA \\\\ \n7.770e+05 \\\\ \n8.880e+06 \\\\ \n\\bottomrule\n\\end{longtable}\n
Does this mean that gt
still do not support colors in this situation, or my implementation is wrong?
This was fixed as described in this discussion.
The output LaTeX code now includes cell background colors:
\\begin{table}[!t]\n\\fontsize{12.0pt}{14.4pt}\\selectfont\n\\begin{tabular*}{\\linewidth}{@{\\extracolsep{\\fill}}r}\n\\toprule\nnum \\\\ \n\\midrule\\addlinespace[2.5pt]\n1.111e-01 \\\\ \n2.222e+00 \\\\ \n3.333e+01 \\\\ \n4.444e+02 \\\\ \n{\\cellcolor[HTML]{E0FFFF}{5.550e+03}} \\\\ \nNA \\\\ \n{\\cellcolor[HTML]{E0FFFF}{7.770e+05}} \\\\ \n{\\cellcolor[HTML]{E0FFFF}{8.880e+06}} \\\\ \n\\bottomrule\n\\end{tabular*}\n\\end{table}\n
Result: