Libre Office issue with `tab_spanner`
Description
table spanners work perfectly in html and pdf format, but the word document output loses the domain of the span when using libre office. Office 365 and Google Docs seem OK as well.
Reproducible example
---
title: "test"
format: docx
---
```{r}
library(gt)
tbl_comp_names <- structure(list(lvl = c("BEBRAS", "Advent of code"),
per = c(79.5,
37.2),
per_grand = c(57.4, 26.9),
grandtotal = c(108L, 108L),
total = c(78L, 78L)),
row.names = c(NA, -2L),
class = c("tbl_df",
"tbl", "data.frame"))
tbl_comp_names %>%
gt() %>%
tab_spanner(
columns = starts_with("per"),
label=("percentage")) %>%
tab_spanner(
columns = ends_with("total"),
label=("n"))
```
Expected result
The span appears like this in RStudio:
But in docx (libre office), it appears like this:
Session info
R version 4.4.1 (2024-06-14 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 11 x64 (build 22631)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8
time zone: Europe/London tzcode source: internal
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] gt_0.11.0 ggtext_0.1.2 janitor_2.2.0 arrow_17.0.0.1 openxlsx_4.2.7.1 labelled_2.13.0
[7] here_1.0.1 haven_2.5.4 glue_1.7.0 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1
[13] dplyr_1.1.4 purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.1
[19] tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] sass_0.4.9 utf8_1.2.4 generics_0.1.3 xml2_1.3.6 stringi_1.8.4
[6] hms_1.1.3 digest_0.6.37 magrittr_2.0.3 grid_4.4.1 timechange_0.3.0
[11] fastmap_1.2.0 rprojroot_2.0.4 zip_2.3.1 fansi_1.0.6 scales_1.3.0
[16] cli_3.6.3 crayon_1.5.3 rlang_1.1.4 bit64_4.5.2 munsell_0.5.1
[21] withr_3.0.1 tools_4.4.1 tzdb_0.4.0 colorspace_2.1-1 assertthat_0.2.1
[26] vctrs_0.6.5 R6_2.5.1 lifecycle_1.0.4 snakecase_0.11.1 bit_4.5.0
[31] vroom_1.6.5 pkgconfig_2.0.3 pillar_1.9.0 gtable_0.3.5 Rcpp_1.0.13
[36] xfun_0.47 tidyselect_1.2.1 knitr_1.48 rstudioapi_0.16.0 htmltools_0.5.8.1
[41] compiler_4.4.1 gridtext_0.1.5
If you put a table label, for instance, #| label: tbl-reg, while you get an incorrect rendering with LibreOffice:
It won't even open in Microsoft Word for Windows, it will say the document contains unreadable content:
Here is a MWE:
---
title: "test"
format: docx
---
```{r}
#| label: tbl-reg
#| echo: false
#| output: true
library(gt)
tbl_comp_names <- structure(list(lvl = c("BEBRAS", "Advent of code"),
per = c(79.5,
37.2),
per_grand = c(57.4, 26.9),
grandtotal = c(108L, 108L),
total = c(78L, 78L)),
row.names = c(NA, -2L),
class = c("tbl_df",
"tbl", "data.frame"))
tbl_comp_names %>%
gt() %>%
tab_spanner(
columns = starts_with("per"),
label=("percentage")) %>%
tab_spanner(
columns = ends_with("total"),
label=("n"))
Regarding your original example (that is, without a label or with a non-tbl label), I get the same results.
Incorrect rendering in LibreOffice:
But correct rendering in Word:
So this looks like two possible bugs: one with and one without a tbl- label, with a bug in Quarto/pandoc that outputs invalid tables in case there is a tbl- label, and a bug in LibreOffice that is unable to correctly render the table in both cases