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

Resize fails in quarto if a table has a note #206

Closed MarcoPortmann closed 6 months ago

MarcoPortmann commented 6 months ago

theme_tt(theme = "resize"... will not work in quarto if the table contains a note:

---
format: 
  pdf

---

```{r message=TRUE, include=FALSE}
library(tidyverse)
library(tinytable)
#| echo: FALSE
#| label: tbl-test
#| tbl-cap: "My table"

tibble(X = 1) %>% 
  tt(note = "abc") %>% 
  theme_tt(theme = "resize", width = 0.9)
This will lead to the following error:

```r
Quitting from lines 13-20 [tbl-test] (testdoc.qmd)
Error:
! The `regex` supplied `lines_drop()` did not match a unique line.
Backtrace:
  1. global .main()
  2. execute(...)
  3. rmarkdown::render(...)
  4. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  5. knitr:::process_file(text, output)
     ...
 26. tinytable::knit_print.tinytable(x, ...)
 27. tinytable:::build_tt(x, output = output)
 29. tinytable:::finalize(x)
 30. tinytable (local) fn(x)
 31. tinytable:::lines_insert(tab, regex = reg, new = new, position = "before")

Execution halted
vincentarelbundock commented 6 months ago

Thanks for the report. Should be fixed on Github:

library(tinytable)
data.frame(X = 1) |>
  tt(note = "abc") |>
  theme_tt(theme = "resize", width = 0.9) |>
  print("latex")
\begin{table}
\centering
\resizebox{\ifdim\width>\linewidth 0.9\linewidth\else\width\fi}{!}{
\begin{talltblr}[         %% tabularray outer open
entry=none,label=none,
note{}={abc},
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]},
}                     %% tabularray inner close
\toprule
X \\ \midrule %% TinyTableHeader
1 \\
\bottomrule
\end{talltblr}
}
\end{table}