-
Notifications
You must be signed in to change notification settings - Fork 217
Open
Labels
Description
Prework
- Read and agree to the code of conduct and contributing guidelines.
- If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
Description
In gt 1.3.0 (but not in 1.2.0, as far as I can tell), using md() inside a column label in a PDF table wrongly causes that column to be set to be the full width of the latex \linewidth.
Reproducible example
---
title: "Untitled"
format: pdf
---
This file illustrates a problem with using `md()` inside a PDF table column heading in gt 1.3.0 that causes the rest of the table to be placed off the page.
This code works as expected and produces @tbl-works:
```{r}
#| label: tbl-works
#| tbl-cap: "Works as expected"
library(gt)
countrypops |>
head(10) |>
gt() |>
cols_label(country_code_2 ~ "country code")
```
But if we use `md()` to break a long column name over multiple lines, the column is assigned the width of `\linewidth` so the rest of the table disappears off the right margin (@tbl-doesnt):
```{r}
#| label: tbl-doesnt
#| tbl-cap: "Does not work as expected"
countrypops |>
head(10) |>
gt() |>
cols_label(country_code_2 ~ md("country<br>code"))
```
PDF output: gt_bug.pdf
Expected result
The column should keep the automatically-assigned width it had previously.
Session info
R version 4.5.2 (2025-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.2
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.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
locale:
[1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8
time zone: Europe/London
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] gt_1.3.0
loaded via a namespace (and not attached):
[1] digest_0.6.39 utf8_1.2.6 R6_2.6.1 fastmap_1.2.0 tidyselect_1.2.1
[6] magrittr_2.0.4 glue_1.8.0 tibble_3.3.1 pkgconfig_2.0.3 htmltools_0.5.9
[11] dplyr_1.1.4 generics_0.1.4 lifecycle_1.0.5 xml2_1.5.2 cli_3.6.5
[16] sass_0.4.10 vctrs_0.7.1 withr_3.0.2 compiler_4.5.2 tools_4.5.2
[21] pillar_1.11.1 rlang_1.1.7 fs_1.6.6
Reactions are currently unavailable