Skip to content

Commit

Permalink
style captions and notes. Finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Dec 12, 2024
1 parent 0752b6c commit a54b815
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: tinytable
Type: Package
Title: Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', and 'Typst' Formats
Description: Create highly customized tables with this simple and dependency-free package. Data frames can be converted to 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', or 'Typst' tables. The user interface is minimalist and easy to learn. The syntax is concise. 'HTML' tables can be customized using the flexible 'Bootstrap' framework, and 'LaTeX' code with the 'tabularray' package.
Version: 0.6.1.2
Version: 0.6.1.3
Imports:
methods
Depends:
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Bugs:

New:

* `style_tt("notes")` can style footnotes.
* `style_tt("notes")` and `style_tt("caption")` can style footnotes and captions. Note: This will only style captions handled by the `caption` argument in `tt()`, and not captions created by Quarto.

Misc:

Expand Down
2 changes: 1 addition & 1 deletion R/finalize_typst.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setMethod(

cap <- x@caption
if (length(cap) == 1) {
out <- sub("$TINYTABLE_TYPST_CAPTION", sprintf("caption: [%s],", cap), out, fixed = TRUE)
out <- sub("$TINYTABLE_TYPST_CAPTION", sprintf("caption: %s,", cap), out, fixed = TRUE)
} else {
out <- sub("$TINYTABLE_TYPST_CAPTION", "", out, fixed = TRUE)
}
Expand Down
5 changes: 4 additions & 1 deletion R/style_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#' This function applies styling to a table created by `tt()`. It allows customization of text style (bold, italic, monospace), text and background colors, font size, cell width, text alignment, column span, and indentation. The function also supports passing native instructions to LaTeX (tabularray) and HTML (bootstrap) formats.
#'
#' @param x A table object created by `tt()`.
#' @param i Row indices where the styling should be applied. Can be a single value, a vector, or a logical matrix with the same number of rows and columns as `x`. `i=0` is the header, and negative values are higher level headers. Row indices refer to rows *after* the insertion of row labels by `group_tt()`, when applicable.
#' @param i Numeric vector, logical matrix, or string..
#' - Numeric vector: Row indices where the styling should be applied. Can be a single value or a vector.
#' - Logical matrix: A matrix with the same number of rows and columns as `x`. `i=0` is the header, and negative values are higher level headers. Row indices refer to rows *after* the insertion of row labels by `group_tt()`, when applicable.
#' - String: "notes" or "caption".
#' @param j Column indices where the styling should be applied. Can be:
#' + Integer vectors indicating column positions.
#' + Character vector indicating column names.
Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/_tinysnapshot/typst-complicated.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#show figure: set block(breakable: true)
#figure( // start figure preamble
caption: [text([Hello World])],
caption: text([Hello World]),
kind: "tinytable",
supplement: "Table", // end figure preamble

Expand Down
7 changes: 6 additions & 1 deletion man/style_tt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions sandbox/typst.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ options(tinytable_quarto_figure = TRUE)
options(tinytable_print_output = "typst")
```

```{r}
tt(head(iris), caption = "Hello World", notes = "This is a note") |>
style_tt("notes", color = "orange", italic = TRUE) |>
style_tt("caption", color = "green", bold = TRUE, strikeout = TRUE)
```


```{r}
# Semi-complicated
tab <- tt(mtcars[1:4, 1:5], caption = "Hello World") |>
Expand Down

0 comments on commit a54b815

Please sign in to comment.