I'm using Quarto. I need to refer to other figures and tables in the caption of figures and tables. References to other figures/tables in the caption of a table work fine when rendered with knitr::kable() but not with kableExtra::kbl(). But I like some of the extras in kableExtra. Is there a way to get references in table captions to work for kableExtra?
Added comment, after initial post: I'm rendering to PDF. Just this moment I tried rendering to HTML, and it all works. So there's something about rendering to PDF that creates the problem.
A complete .qmd document with a minimal example is appended below, but here are highlights. There's already a simple figure displayed, referenced by @fig-A. I set up a matrix in R, called d_mat. When I display the matrix as a table using knitr::kable(), the reference in the caption is resolved as 'Figure 1', like this:
#| echo: FALSE
#| label: tbl-kable
#| tbl-cap: "This is a table with `knitr::kable()`. Compare with @fig-A."
knitr::kable( d_mat )
But when I display the matrix as a table using kableExtra::kbl(), the reference in the caption is not resolved, like this:
#| echo: FALSE
#| label: tbl-kbl
#| tbl-cap: "This is a table with `kableExtra::kbl()`. Compare with @fig-A."
kableExtra::kbl( d_mat )
Is there a fix? Thanks for reading!
Complete .qmd document:
---
title: "Table Test"
---
```{r}
#| echo: FALSE
#| label: fig-A
#| fig-cap: "This is a figure. Compare with @tbl-kable."
#| fig-pos: "!tbph" # for LaTeX floating figures
plot( 0 , 0 )
```
```{r}
#| echo: FALSE
d_mat <- matrix( 1:12 , nrow=3 ,
dimnames=list( Rows=c("R1","R2","R3"),
Columns=c("C1","C2","C3","C4") ) )
```
```{r}
#| echo: FALSE
#| label: tbl-kable
#| tbl-cap: "This is a table with `knitr::kable()`. Compare with @fig-A."
knitr::kable( d_mat )
```
```{r}
#| echo: FALSE
#| label: tbl-kbl
#| tbl-cap: "This is a table with `kableExtra::kbl()`. Compare with @fig-A."
kableExtra::kbl( d_mat )
```
**The caption of @fig-A resolves the reference to the table.**
**The caption of using `knitr::kable` in @tbl-kable resolves the reference to the figure.**
**The caption of using `kableExtra::kbl` in @tbl-kbl does *not* resolve the reference to the figure.**


Answers is just an extension of comments. All source files/logs are available under http://www.sapijaszko.net/up/aaa.zip
And pandoc version: