Closed andrewheiss closed 2 months ago
Well that was an annoying one to diagnose. Turns out that tabularray
modifies the booktabs
syntax and requires square brackets rather than parentheses. This is what I was doing all along, but when we run theme_tt("tabular")
, we revert back to standard booktabs
and need to sub []
for ()
.
Should be fixed on Github now.
Wow that's exceptionally obscure!
Oh wait, maybe this is related. I thought that theme_tt("tabular", style = "tabularray")
would still emit a tabularray-based table bc of the style
argument, but
tt(mtcars[1:5, ]) |>
group_tt(j = list("Things here" = 2:3)) |>
style_tt(
tabularray_inner = "cells={font=\\footnotesize}"
) |>
theme_tt("tabular", style = "tabularray")
emits a plain old tabular:
\begin{tabular}{lllllllllll}
\hline
& Things here & & & & & & & & & \\ \cmidrule(lr){2-3}
mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb \\ \hline
21.0 & 6 & 160 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 & 4 \\
21.0 & 6 & 160 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4 & 4 \\
22.8 & 4 & 108 & 93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 & 1 \\
21.4 & 6 & 258 & 110 & 3.08 & 3.215 & 19.44 & 1 & 0 & 3 & 1 \\
18.7 & 8 & 360 & 175 & 3.15 & 3.440 & 17.02 & 0 & 0 & 3 & 2 \\
\hline
\end{tabular}
while this
tt(mtcars[1:5, ]) |>
group_tt(j = list("Things here" = 2:3)) |>
style_tt(
tabularray_inner = "cells={font=\\footnotesize}"
)
emits the tabularray tblr
environment:
\begin{table}
\centering
\begin{tblr}[ %% tabularray outer open
] %% tabularray outer close
{ %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]Q[]},
cell{1}{2}={c=2,}{halign=c,},
cells={font=\footnotesize},
} %% tabularray inner close
\toprule
& Things here & & & & & & & & & \\ \cmidrule[lr]{2-3}
mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb \\ \midrule %% TinyTableHeader
21.0 & 6 & 160 & 110 & 3.90 & 2.620 & 16.46 & 0 & 1 & 4 & 4 \\
21.0 & 6 & 160 & 110 & 3.90 & 2.875 & 17.02 & 0 & 1 & 4 & 4 \\
22.8 & 4 & 108 & 93 & 3.85 & 2.320 & 18.61 & 1 & 1 & 4 & 1 \\
21.4 & 6 & 258 & 110 & 3.08 & 3.215 & 19.44 & 1 & 0 & 3 & 1 \\
18.7 & 8 & 360 & 175 & 3.15 & 3.440 & 17.02 & 0 & 0 & 3 & 2 \\
\bottomrule
\end{tblr}
\end{table}
But I might be doing something wrong
Like, this is probably a separate issue, but my ultimate dream use case is to do something like this to get tabularray features and Quarto cross-referencing abilities both in and out of the custom crossref environment:
---
title: "Testing"
format:
pdf:
keep-tex: true
crossref:
custom:
- kind: float
key: apptbl
latex-env: apptbl
reference-prefix: Table A
space-before-numbering: false
latex-list-of-description: Appendix Table
apptbl-cap-location: top
---
@tbl-test has footnote-sized text and isn't in the appendix
```{r}
#| label: tbl-test
#| tbl-cap: Regular table
library(tinytable)
tt(mtcars[1:5, ]) |>
group_tt(j = list("Things here" = 2:3)) |>
style_tt(
tabularray_inner = "cells={font=\\footnotesize}"
)
@apptbl-testing should also have footnote-sized text but use appendix numbering
::: {#apptbl-testing}
tt(mtcars[1:5, ]) |>
group_tt(j = list("Things here" = 2:3)) |>
style_tt(
tabularray_inner = "cells={font=\\footnotesize}"
) |>
theme_tt("tabular", style = "tabularray")
Appendix table.
:::
Currently the first table works:
<img width="601" alt="image" src="https://github.com/user-attachments/assets/1ac9f283-b939-47e7-ac13-2088a5af6498">
But the second table doesn't use tabularray:
<img width="666" alt="image" src="https://github.com/user-attachments/assets/9f4e0ba0-e049-4ab6-84e9-c5406a82e8fb">
@andrewheiss love those power user feature requests!
There was definitely a bug.
I think your fancy example should work as expected now.
It works!!
Love to see this!
Related to #293 and #301 and the new
theme_tt("tabular", style = "tabularray")
for working with custom cross reference sections, when usinggroup_tt(j = ...)
andtheme_tt("tabular", style = "tabularray")
, there's a LaTeX error: "Missing number, treated as zero."This works:
This doesn't work:
…and with this error: