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

Continuation of a multipage table does not start on a new page #209

Closed MarcoPortmann closed 6 months ago

MarcoPortmann commented 6 months ago

The following example creates a multi-page table. However, the continuation of the table starts directly after the first table instead of starting on a new page, and the continuation extends beyond the margin.

---
title: "Quarto Document"
format: pdf

---

```{r include=FALSE}
library(tidyverse)
library(tinytable)

This is @tbl-test.

#| label: tbl-test
#| tbl-cap: "Table Caption"
 rbind(mtcars, mtcars) %>% 
   tt() %>% 
   theme_tt(theme = "multipage", rowhead = 1)

![image](https://github.com/vincentarelbundock/tinytable/assets/7468121/165c8f42-b85e-4d7a-aa70-183a8a3d872a)

I'm also not sure how to specify the labels and captions correctly. My previous understanding was that the use of referenceable labels requires the use of `#| label: ...`and `#| tbl-cap: ...` instead of `tt(caption = ...)` (does #208 refer to this issue?).
vincentarelbundock commented 6 months ago

The problem is that when you use the tbl-cap tag in Quarto, it will wrap the table in a floating LaTeX environment , which pushes it down and looks weird.

So for long tables, you cannot use that and must use the caption argument instead, possibly including a \\label{} call directly in there.

Unfortunately, when supporting so many different output formats, it's hard to be 100% consistent. But I already plan to at least document this better in the future. Follow progress here: https://github.com/vincentarelbundock/tinytable/issues/208

MarcoPortmann commented 6 months ago

I could cope with this inconsistency. However, it seems that crossref doesn't work that way:

---
title: "Quarto Document"
format: pdf

---

```{r include=FALSE}
library(tidyverse)
library(tinytable)

This is @tbl-test.

 rbind(mtcars, mtcars) %>% 
   tt(caption = "Hello world\\label{tbl-test}") %>% 
   theme_tt(theme = "multipage", rowhead = 1)


![image](https://github.com/vincentarelbundock/tinytable/assets/7468121/1298abd1-0732-4ac5-a9bb-047f15011403)
vincentarelbundock commented 6 months ago

What does the raw latex file look like? Maybe Quarto tweaks the labels automatically?

MarcoPortmann commented 6 months ago

The \label{tbl-test} seems fine to me.

This is \textbf{?@tbl-test}.

\begin{longtblr}[         %% tabularray outer open
caption={Hello world\label{tbl-test}},
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]},
rowhead=1,
}                     %% tabularray inner close
\toprule
vincentarelbundock commented 6 months ago

My guess is Quarto will only recognize the @ syntax if it handles everything, including the label chunk option.

You might have to use \ref{} in the text, although this won't be cross platform.

This is one of the problems of using quarto, which is a layer on top of pandoc, a layer on top of latex, a layer on top of tex...

vincentarelbundock commented 5 months ago

Circling back to this to note that I've exchanged with Quarto developers, and have learned that the problem is that Quarto automatically wraps tables in an floating table environment, which causes a conflict with tabularray's longtblr environment.

Unfortunately, there is nothing I can do about this multipage problem, since there's currently no way to disable that Quarto feature.

I filed a feature request, but don't know if it will be implemented upstream.

In the meantime, a workaround is to work with pure LaTeX labels, as is now documented in the vignette.

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

And then refer to tables with \ref{tbl-ex-multipage} as any other LaTeX reference.

Thanks again for raising this issue.