-
Notifications
You must be signed in to change notification settings - Fork 217
Open
Labels
Description
Description
Calling as_latex() on a gt table that uses summary_rows()/grand_summary_rows() plus stub styling (cells_stub_summary(), cells_stub_grand_summary()) throws a LaTeX error:
Error in if (!grepl("\shortstack[l]", x, fixed = TRUE)) { : argument is of length zero}.
This used to work with older gt versions ( such as 1.0, but not after ! ).
Reproducible example
library(gt)
library(dplyr)
library(tidyr)
df <- tibble(
grp = c("G1","G1","G2"),
row = c("r1","r2","r3"),
level = c("1A","2A","1A"),
val = c(1,2,3)
)
tbl <- df |>
pivot_wider(names_from = level, values_from = val, values_fill = 0) |>
gt(rowname_col = "row", groupname_col = "grp") |>
summary_rows(columns = where(is.numeric), fns = list("Sous total" = ~sum(.))) |>
grand_summary_rows(columns = where(is.numeric), fns = list("Total général" = ~sum(.))) |>
tab_style(
style = cell_text(weight = "bold", align = "right"),
locations = list(cells_stub_summary(), cells_stub_grand_summary())
) |>
tab_spanner(label = "Group BOB", columns = c(`1A`, `2A`)) |>
cols_label(starts_with("1") ~ "")
as_latex(tbl)
as_latex(tbl) should return valid LaTeX without error; summary rows and their stub styling should render normally. Works well on html output.
Thanks so much for your help and for maintaining gt.
Reactions are currently unavailable