vincentarelbundock / tinytable

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

Issues with group_tt() and notes in Quarto + typst #278

Closed maibennett closed 4 months ago

maibennett commented 5 months ago

Hi! I'm working on a document using Quarto + typst, and for some reason the tables are not rendering as they do in the console. Here's a short example (the .qmd file) that is similar to what I'm trying to do:

---
title: "Example tiny table"
format:
  typst:
    toc: false
    section-numbering: 1.1.a
    columns: 1
---

```{r, echo=FALSE, message=FALSE, warning=FALSE}
library(dplyr)
library(tinytable)

@tbl-tab1 is the table I want, but when rendering the document, the groups do not appear (they do appear on the console if I print the table there.)

#| label: tbl-tab1
#| tbl-cap: "lorem ipsum"

df = data.frame(Meas = rep(c("meas1 (\\$)", "meas2 (pts)", "meas3"), 2),
                y1 = c(1:3, 6:8),
                y2 = c(1:3, 6:8) + 1,
                y3 = c(1:3, 6:8) + 2,
                y4 = c(1:3, 6:8) + 5)

tt(df) %>% style_tt(j=1:ncol(df), align = "lrrrr") %>% format_tt(escape = TRUE) %>% style_tt(fontsize = 0.8) %>%
  group_tt(i = list("Var1" = 1,
                    "Var2" = 4))

Same thing with @tbl-tab2 and notes.

#| label: tbl-tab2
#| tbl-cap: "lorem ipsum"

tt(df, notes = "Notes: This is a note") %>% style_tt(j=1:ncol(df), align = "lrrrr") %>% 
format_tt(escape = TRUE) %>% style_tt(fontsize = 0.8)


If I run each chunk of code, they print fine on the console:

![console](https://github.com/vincentarelbundock/tinytable/assets/22154053/b4d1053b-63fa-4623-b216-bfcf8c273034)

But they don't render correctly, and both group_tt() and the notes option are ignored:

![pdf_output](https://github.com/vincentarelbundock/tinytable/assets/22154053/9d2f5857-dd39-4db8-8fbe-4070b770d2a5)

If anyone knows why this could be happening, I'd really appreciate it! Thanks 

PS: This is a beautiful package, so thank you for all the work on this
vincentarelbundock commented 5 months ago

Thanks for taking the time to craft an example. I'll look into it when I get back home to my computer.

vincentarelbundock commented 5 months ago

With the latest from GitHub, it looks like things are working OK. The only thing to be careful about is that we should not escape the \\$ manually in the creation of the data frame if we're going to use format_tt(escape=TRUE). Typst does not play well with double escapes, apparently. So you need:

df = data.frame(Meas = rep(c("meas1 ($)", "meas2 (pts)", "meas3"), 2),
                y1 = c(1:3, 6:8),
                y2 = c(1:3, 6:8) + 1,
                y3 = c(1:3, 6:8) + 2,
                y4 = c(1:3, 6:8) + 5)

Also, I noted two limitations of Typst that came up in my tests: lack of indentation and row-specific alignment. I'll look into those in separate issues:

https://github.com/vincentarelbundock/tinytable/issues/280 https://github.com/vincentarelbundock/tinytable/issues/279

maibennett commented 5 months ago

Thanks for the quick response! I'll update appropriately :) (I double escaped because typst was complaining before)