vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
196 stars 16 forks source link

Labels/cross-references not working in "multipage" table #229

Closed arcruz0 closed 5 months ago

arcruz0 commented 5 months ago

Hi and thanks for the great package! Please see the following .qmd MRE:

---
title: "Example"
format: pdf
---

```{r}
library(tinytable)
```

@tbl-ex-multipage says...

```{r}
tt(rbind(mtcars, mtcars), 
   caption = "Example table. \\label{tbl-ex-multipage}") |>
  theme_tt("multipage")
```

In the rendered PDF, the cross-reference doesn't work (rendering gives the warning: "WARNING: Unable to resolve crossref @tbl-ex-multipage"):

image

This issue has showed up previously in #209 in connection with Quarto. But I think the problem is not with Quarto, as I can also reproduce in raw LaTeX. Instead, I think the problem's the following. As multipage repeats the caption over multiple pages, attaching the label to the caption results in multiple labels being created.

If I manually change the output .tex to include a label={} argument in the longtblr call (instead of using \label{} inside of the caption argument), then cross-referencing works as expected. Perhaps the issue could be solved with a dedicated label = argument in tt(), which would resolve to using the label={} argument in the multipage case? Alternatively, theme_tt() could parse the tt() object to detach the label from the caption in the .tex output.

Many thanks in advance!

vincentarelbundock commented 5 months ago

Thanks for the report and diagnostics. In principle, you should be able to use the tabularray_outer argument to insert the label. However, unlike you, I am unable to make cross-referencing work, even when adding label.

In this example, the "manual" latex reference works for PDF, but not the other. Both references fail in HTML.

What are you doing differently?

---
title: "Example"
format: 
    pdf:
        keep-tex: true
    html: default
---

```{r}
library(tinytable)

Table \ref{tbl-ex-multipage}

@tbl-ex-multipage says...

tt(rbind(mtcars, mtcars), caption = "Example table.") |>
  style_tt(tabularray_outer = "label={tbl-ex-multipage}") |>
  theme_tt("multipage")
arcruz0 commented 5 months ago

We do we get the same result. My apologies; I checked the cross-referencing on LaTeX, but not on Quarto with the @tbl- syntax. After experimenting a bit, I couldn't get the the @tbl- syntax to work in any way (as you predicted in #209—I suppose this is indeed an upstream Pandoc/Quarto issue).

Still, this style_tt() + \ref{} workaround is acceptable for my use-case. So thank you so much!

vincentarelbundock commented 5 months ago

Good to hear.

Let's leave the issue open until I have a more general solution. Also, please be aware that behavior might change in the future once I find a permanent solution.

vincentarelbundock commented 5 months ago

Unfortunately, there cannot be a general or cleaner solution for now, because of Quarto-specific reasons explained here: https://github.com/quarto-dev/quarto-cli/discussions/9332

I have improved the documentation and the vignette to provide clearer guidelines for users.

Thanks for raising this!