Closed kazuyanagimoto closed 2 months ago
Yes, it is an expected behavior. When users in Quarto use the tbl-cap
or tbl-label
chunk options, Quarto inserts the table in an environment, and there can be conflict with an existing environment. Therefore, to avoid duplication of environments and conflicts, tinytable
does not create figures in Quarto, and recommends that users call the appropriate chunk options.
Thank you for your quick response! I understand it. But for the presentation, I would like to use tables without label
or tbl-cap
. I think captions are redundant in a presentation. Also, I would like to use style_tt()
to highlight a table line by line, and it is time-consuming to re-label all tables just to highlight one line. If I put different labels on these tables, the table number will be counted up by highlighting.
So I expect that tinytable
puts a table in the figure
environment if label
is not provided in the current Quarto chunk (possibly in R/finalize_typst.R?)
Sounds reasonable.
Check out the vignette on how to define custom themes. You can apply those these automatically via a global option, and use that the structure to automatically add the figure environment "manually"
Thank you. I tried this
theme_slides <- function(x, ...) {
fn <- function(table) {
table@table_string <- paste0("#figure([\n", table@table_string, "\n])")
return(table)
}
style_tt(x, finalize = fn)
}
options(tinytable_tt_theme = theme_slides)
However, it does not correctly work because while it adds the figure environment, it removes some table.hline
and produces a table without top and bottom solid lines. It seems related to R/style_typst.R
L159-L180, but I couldn't figure it out. Can I ask how to write such a theme?
Does this work for you?
theme_slides <- function(x, ...) {
fn <- function(table) {
if (isTRUE(table@output == "typst")) {
table@table_string <- paste0("#figure([\n", table@table_string, "\n])")
}
return(table)
}
x <- style_tt(x, finalize = fn)
return(x)
}
tt(head(iris), theme = theme_slides)
No. This code removes some table.hline
in the original table. You can see the difference by this example.
---
format: typst
---
```{r}
library(tinytable)
theme_slides <- function(x, ...) {
fn <- function(table) {
if (isTRUE(table@output == "typst")) {
table@table_string <- paste0("#figure([\n", table@table_string, "\n])")
}
return(table)
}
x <- style_tt(x, finalize = fn)
return(x)
}
tt(head(iris))
tt(head(iris), theme = theme_slides)
Right, sorry, you also need to apply the default theme:
theme_slides <- function(x, ...) {
fn <- function(table) {
if (isTRUE(table@output == "typst")) {
table@table_string <- paste0("#figure([\n", table@table_string, "\n])")
}
return(table)
}
x <- style_tt(x, finalize = fn)
x <- theme_tt(x, theme = "default")
return(x)
}
Now, it works! Thank you for your quick response!
@kazuyanagimoto
FYI, I added a global option to do this more easily. It should work in the main
branch on Github and will be part of the next release.
options(tinytable_quarto_figure = TRUE)
Thanks again for your quick and frequent development of the package!
Hi, I am using this package for Quarto + Typst environment. I found that if the label is not specified in the Quarto chunk, the generated typst table is not in the
#figure([])
environment. While this is not a problem in a regular Typst article, it gets an error in the Touying environment.I am developing a slide template Quarto + Typst with Touying. In the demo slides, I manually add
#figure([
and])
before and aftertinytable
object in the code.Is this non-
figure
output in Quarto + Typst an expected behavior? If so, is it possible to add an option to put the table infigure
environment?