diff --git a/R/finalize_typst.R b/R/finalize_typst.R index df26ca88..18f7eec2 100644 --- a/R/finalize_typst.R +++ b/R/finalize_typst.R @@ -6,5 +6,12 @@ finalize_typst <- function(x) { out <- sub("$TINYTABLE_TYPST_NCOL", meta(x, "ncols"), out, fixed = TRUE) out <- sub("$TINYTABLE_TYPST_NHEAD", meta(x, "nhead"), out, fixed = TRUE) + cap <- meta(x, "caption") + if (!is.null(cap)) { + out <- sub("$TINYTABLE_TYPST_CAPTION", sprintf("caption: [%s],", cap), out, fixed = TRUE) + } else { + out <- sub("$TINYTABLE_TYPST_CAPTION", "", out, fixed = TRUE) + } + return(out) } \ No newline at end of file diff --git a/R/tt_typst.R b/R/tt_typst.R index 7acc4b94..f4d3e0ba 100644 --- a/R/tt_typst.R +++ b/R/tt_typst.R @@ -26,6 +26,7 @@ tt_typst <- function(x, caption, theme, width, notes, ...) { out <- style_typst(out, i = seq(1, meta(out)$nrows, by = 2), background = "#ededed") } + class(out) <- c("tinytable", "knit_asis", class(out)) return(out) } diff --git a/inst/templates/typst.typ b/inst/templates/typst.typ index 622e6c6a..4a8046c3 100644 --- a/inst/templates/typst.typ +++ b/inst/templates/typst.typ @@ -3,20 +3,24 @@ #let nrow = $TINYTABLE_TYPST_NROW; #let ncol = $TINYTABLE_TYPST_NCOL; -#tablex( - columns: ncol, - header-rows: nhead, - align: left + horizon, - auto-lines: false, +#figure( + $TINYTABLE_TYPST_CAPTION + tablex( + columns: ncol, + header-rows: nhead, + align: left + horizon, + auto-lines: false, - // tinytable lines before + // tinytable lines before - map-cells: cell => { + map-cells: cell => { - // tinytable cell style before - return cell; - }, + // tinytable cell style before + return cell; + }, - // tinytable cell content after + // tinytable cell content after + + ) // end tablex +) // end figure -)