From dc7d97ad7774be34d279c392db02553b31e0a73e Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Sun, 14 Jan 2024 07:35:28 -0500 Subject: [PATCH] style_tt refactor complete --- R/style_tt.R | 22 ++++++++++------------ vignettes/tutorial.qmd | 5 ++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/R/style_tt.R b/R/style_tt.R index fc32ff65..adffac7e 100644 --- a/R/style_tt.R +++ b/R/style_tt.R @@ -100,12 +100,16 @@ style_tt <- function( assert_integerish(j, lower = 1, upper = attr(x, "ncol")) - if (component == "cell") { + if (inherits(x, "tinytable_tabularray")) { + if (component == "cell") { + idx <- expand.grid(i = i, j = j) + } else if (component == "row") { + idx <- data.frame(i = i) + } else if (component == "col") { + idx <- data.frame(j = j) + } + } else { idx <- expand.grid(i = i, j = j) - } else if (component == "row") { - idx <- data.frame(i = i) - } else if (component == "col") { - idx <- data.frame(j = j) } # do not style header by default. JS index starts at 0 @@ -195,13 +199,7 @@ style_tt <- function( } # Apply Tabularray command - if (any(c("colspan", "rowspan") %in% names(tabularray))) { - span <- tabularray[names(tabularray) %in% c("colspan", "rowspan")] - span <- paste(span, collapse = ",") - tabularray <- tabularray[!names(tabularray) %in% c("colspan", "rowspan")] - } else { - span <- "" - } + span <- if (!is.null(colspan)) paste0("c=", colspan, ",") else "" if (inherits(x, "tinytable_tabularray")) { for (k in seq_len(nrow(idx))) { diff --git a/vignettes/tutorial.qmd b/vignettes/tutorial.qmd index d95bf07a..699ccf99 100644 --- a/vignettes/tutorial.qmd +++ b/vignettes/tutorial.qmd @@ -179,12 +179,15 @@ dat <- data.frame(Math = c("\\( x^2 + y^2 = z^2 \\)", "\\( \\frac{1}{2} \\)")) tt(dat, align = "c") ``` -```{r, eval = knitr::is_latex_output()} +::: {.content-visible when-format="pdf"} In LaTeX (PDF), you can also use the `mode` inner setting from `tabularray` to render math in tables without delimiters (see @sec-tabularray for details on `tabularray`): +```{r, eval = knitr::is_latex_output()} + dat <- data.frame(Math = c("x^2 + y^2 = z^2", "\\frac{1}{2}")) tt(dat, align = "c") |> style_tt(tabularray_inner = "column{1}={mode=math},") ``` +::: # Style