gt
gt copied to clipboard
Quarto output to latex breaks when more than one gt table changes table width
Prework
- [x] Read and agree to the code of conduct and contributing guidelines.
- [x] If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
Description
Adding tab_options(table.width="100%")
will now properly adjust the width of the table in the PDF output of Quarto. However, this will only work when it is applied to a single table. Applying it to more than one table generates an error in latex processing. The error is:
LaTeX Error: Command \holdLTleft already defined.
Or name \end... illegal, see p.192 of the manual.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.277 \newlength\holdLTleft
\newlength\holdLTright\setlength\holdLTleft{\LTle...
see test.log for more information.
I believe the issue is that a command is trying to be defined each time this option is included rather than at the top or in the preamble of the latex document.
Reproducible example
- [x] Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. 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.
The following quarto document will reproduce the error. Remove either one of the calls to tab_options
and the error will go away.
---
title: "test"
format: pdf
---
```{r}
library(gt)
library(dplyr)
```
```{r}
start_date <- "2010-06-07"
end_date <- "2010-06-14"
sp500 |>
dplyr::filter(date >= start_date & date <= end_date) |>
dplyr::select(-adj_close) |>
gt() |>
tab_header(
title = "S&P 500",
subtitle = glue::glue("{start_date} to {end_date}")
) |>
fmt_currency() |>
fmt_date(columns = date, date_style = "wd_m_day_year") |>
fmt_number(columns = volume, suffixing = TRUE) |>
tab_options(table.width = "100%")
```
```{r}
islands_tbl <-
tibble(
name = names(islands),
size = islands
) |>
arrange(desc(size)) |>
slice(1:10)
gt(islands_tbl[1:2,]) |>
tab_header(
title = md("**Large Landmasses of the World**"),
subtitle = md("The *top two* largest are presented")
) |>
tab_options(table.width = "100%")
```
Expected result
The quarto document should have rendered to PDF without error and with both tables as full width.
Session info
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.3.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/Los_Angeles
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_1.1.4 gt_0.10.1
loaded via a namespace (and not attached):
[1] digest_0.6.34 utf8_1.2.4 R6_2.5.1 fastmap_1.1.1 xfun_0.42 tidyselect_1.2.0 magrittr_2.0.3
[8] glue_1.7.0 tibble_3.2.1 knitr_1.45 htmltools_0.5.7 pkgconfig_2.0.3 generics_0.1.3 lifecycle_1.0.4
[15] xml2_1.3.6 cli_3.6.2 fansi_1.0.6 sass_0.4.8 vctrs_0.6.5 withr_3.0.0 compiler_4.3.2
[22] rstudioapi_0.15.0 tools_4.3.2 commonmark_1.9.1 bigD_0.2.0 pillar_1.9.0 rlang_1.1.3 markdown_1.12
@rich-iannone Mea Culpa. This is from code I submitted in a PR. I will figure out why it's not working as it should and send a PR with a fix hopefully this week.
Hi, is this fixed? I still ran into this problem.
@reddylee, it's fixed in the development version, and I think it will be included in the v10.2 release.