Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbered table captions broken #1948

Closed
martinschmelzer opened this issue Jan 29, 2025 · 4 comments · Fixed by #1949
Closed

Numbered table captions broken #1948

martinschmelzer opened this issue Jan 29, 2025 · 4 comments · Fixed by #1949
Assignees
Milestone

Comments

@martinschmelzer
Copy link

martinschmelzer commented Jan 29, 2025

Description

Up until lately, using the caption argument of gt::gt() worked to get numbered captions when compiling to bookdown::html_document2.

With [email protected] the following example delivers the expected caption ("Table 1: Cars"). With [email protected] however, I get "(#tab:Tab1)Cars".

Reproducible example

---
title: "Test"
output: bookdown::html_document2
date: "2025-01-17"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
library(gt)
```

```{r Tab1}
gt::gt(head(mtcars), caption = gt::html("Cars"))
```

Expected result

A table with caption "Table 1: Cars"

Session info

## R version 4.4.2 (2024-10-31)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: Europe/Berlin
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] dplyr_1.1.4 gt_0.11.1  
## 
## loaded via a namespace (and not attached):
##  [1] vctrs_0.6.5       cli_3.6.3         knitr_1.49.7      rlang_1.1.5      
##  [5] xfun_0.50         generics_0.1.3    jsonlite_1.8.9    glue_1.8.0       
##  [9] htmltools_0.5.8.1 sass_0.4.9        rmarkdown_2.29.1  evaluate_1.0.3   
## [13] jquerylib_0.1.4   tibble_3.2.1      fastmap_1.2.0     yaml_2.3.10      
## [17] lifecycle_1.0.4   bookdown_0.42.1   compiler_4.4.2    pkgconfig_2.0.3  
## [21] rstudioapi_0.17.1 digest_0.6.37     R6_2.5.1          tidyselect_1.2.1 
## [25] pillar_1.10.1     magrittr_2.0.3    bslib_0.8.0       tools_4.4.2      
## [29] xml2_1.3.6        cachem_1.1.0
@olivroy
Copy link
Collaborator

olivroy commented Jan 29, 2025

Sorry about that! This is likely due to #1800.

As a workaround for now, you can use Quarto.

---
title: "Test"
format: html
date: today
execute: 
  echo: false
---


```{r}
#| include: false
library(gt)
```

```{r}
#| label: tbl-test
#| tbl-cap: "Cars"
gt(head(cars))
```

Note that captioning and cross-references are handled by Quarto directly..

Image

edit: pdf output works. Reverting to 0.11.0 would probably work too. We'd just need to do a patch to only apply certain fixups for LaTeX output, but not for html one. cc @nielsbock

@martinschmelzer
Copy link
Author

I use extensive custom formats based on pagedown::html_paged to create different reports at work. As far as I know, paged.js is not yet (well) supported by Quarto?
The easiest workaround for me right now is probably to stick to an older version of gt.

@olivroy
Copy link
Collaborator

olivroy commented Jan 30, 2025

@martinschmelzer Thanks again for the report!

Should be fixed with the dev version of gt! pak::pak("rstudio/gt").
Feel free to report back if something is not working as expected.

@martinschmelzer
Copy link
Author

I can confirm its fixed, thanks!

@olivroy olivroy added this to the v0.12.0 milestone Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants