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

support for landscape pages #250

Closed aghaynes closed 4 months ago

aghaynes commented 4 months ago

related to #249

Rather than going for full rotational support (i.e. user defined angles, which is doable in typst), I opted for landscape (-90 degree rotation)

The latex implementation is untested (I think I may even have broken my tex installation in trying to install tabularray :( ). Can you try it, @vincentarelbundock?

Users will probably have to add either lscape and/or pdflscape to their headers (I dont remember which and I'm not sure if/how you handle it with tabularray):

header-includes: |
      \usepackage{pdflscape}
vincentarelbundock commented 4 months ago

Thanks for giving this a shot, I appreciate it!

Unfortunately, I'm not sure that's going to work for every use-case. The Typst case is a bit more complicated because there are two main cases:

  1. Standalone or Quarto without a label: tinytable encloses the table in a #figure environment.
  2. Quarto with a #| label: tbl-blahblah chunk option: tinytable removes the #figure() environment.

So we can't just add something at the start of the template, because the start sometimes gets removed when Quarto takes over.

A less committal way to do this would be to add a theme_tt("rotate") option. Themes are nice, because they don't need to work in every format. They can also be thought of as a "sandbox" where we can implement features that eventually "graduate" to a full-fledged argument. We can also have theme-specific arguments like the degrees, which would allow users to control the orientation of landscape.

In this PR, I implemented minimal support: https://github.com/vincentarelbundock/tinytable/pull/251

There are still problems with my approach, there, as you can see in the screenshot.

I'm not sure if/when I'll have time to work on this more, but perhaps that gives you something to play with if you want to.

caption

aghaynes commented 4 months ago

Under what circumstances do you think it wont work? It seems to work fine for the two cases you mentioned... same with label and captions individually...

```{r}
#| label: tbl-tt
#| tbl-cap: A tinytable object
mtcars[, 1:3] |> head() |> tinytable::tt(landscape = TRUE)
mtcars[, 1:3] |> head() |> tinytable::tt(landscape = TRUE)


![image](https://github.com/vincentarelbundock/tinytable/assets/6594028/5c2b7c4a-fd8d-469d-bd2a-e5753147e96f)

(I dont have a major issue with the theme approach either to be honest - it's similar to the concepts in gt, gtsummary, etc, so if you'd prefer to go down that route...)
vincentarelbundock commented 4 months ago

Well, in landscape the label needs to be rotated as well. Otherwise you have to flip the page twice...

aghaynes commented 4 months ago

Haha... indeed... For that I assume the rotate command would have to go around the whole figure block that quarto applies...

#figure([
#block[
#rotate(-90deg, reflow: true,
[
#let nhead = 1;

would need to be

#rotate(-90deg,
figure([
#block[
#rotate(-90deg, reflow: true,
[
#let nhead = 1;

Could that be handled by the theme method?

vincentarelbundock commented 4 months ago

That's precisely the problem. In Quarto documents, Quarto automatically wraps the whole content that tinytable produces in its own #figure environment. That happens after tinytable is done working, so we no longer have control over anything at that stage, so we can't wrap Quarto's figure in a #rotate

aghaynes commented 4 months ago

Then i'll post a question/request at quarto for it...

vincentarelbundock commented 4 months ago

Then i'll post a question/request at quarto for it...

Good idea. But try not to introduce tinytable into your question. Better to make it a truly minimal example, and ask how to landscape a Typst figure in Quarto, generally.

aghaynes commented 4 months ago

lua filters are the answer... this discussion includes one... https://github.com/quarto-dev/quarto-cli/discussions/9705

vincentarelbundock commented 4 months ago

This is very cool, but it appears to kill the Quarto tbl-cap caption.

vincentarelbundock commented 4 months ago

Also, maybe it sets text in the middle too? not sure

aghaynes commented 4 months ago

I've not tried it out yet. Had to head off.

Looks like they're considering adding it as a quarto feature even!

aghaynes commented 4 months ago

this also works by putting raw typst cells before and after the table producing code, so I propose we close this PR (and possibly also #251) without merging...

```{=typst}
#rotate(-90deg, reflow: true, [
#| tbl-cap: blah blah blah
#| label: tbl-base
head(mtcars) |> tinytable::tt()
])
vincentarelbundock commented 4 months ago

Ah thanks, that's useful. I'll close this one but keep the other one open. It might sitll be useful for LaTex...