-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb89d52
commit dfac54e
Showing
7 changed files
with
123 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
group_typst <- function(x, i = NULL, j = NULL, ...) { | ||
out <- x | ||
|
||
if (!is.null(i)) { | ||
out <- group_typst_row(out, i) | ||
} | ||
|
||
if (!is.null(j)) { | ||
out <- group_typst_col(out, j) | ||
} | ||
|
||
return(out) | ||
} | ||
|
||
|
||
group_typst_col <- function(x, j, ...) { | ||
m <- meta(x) | ||
out <- x | ||
miss <- as.list(setdiff(seq_len(m$ncols), unlist(j))) | ||
miss <- stats::setNames(miss, rep(" ", length(miss))) | ||
j <- c(j, miss) | ||
max_col <- sapply(j, max) | ||
idx <- order(max_col) | ||
j <- j[idx] | ||
lab <- names(j) | ||
len <- sapply(j, length) | ||
col <- sprintf("colspanx(%s, align: center)[%s],", len, lab) | ||
col <- paste(col, collapse = "") | ||
out <- typst_insert(out, col, type = "body") | ||
return(out) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
#import "@preview/tablex:0.0.8": tablex, hlinex, vlinex, colspanx | ||
#let nhead = 2; | ||
#let nrow = 4; | ||
#let ncol = 5; | ||
|
||
#figure( | ||
caption: [Hello World], | ||
tablex( | ||
columns: ncol, | ||
header-rows: nhead, | ||
align: left + horizon, | ||
auto-lines: false, | ||
|
||
hlinex(y: 0, start: 0, end: 5, stroke: 0.1em + black), | ||
hlinex(y: 2, start: 0, end: 5, stroke: 0.05em + black), | ||
hlinex(y: 6, start: 0, end: 5, stroke: 0.1em + black), | ||
// tinytable lines before | ||
|
||
map-cells: cell => { | ||
|
||
|
||
|
||
|
||
let i = (0,1,2,3,4,5,); | ||
let j = (0,); | ||
|
||
if (i.contains(cell.y) and j.contains(cell.x)) { cell.content = emph(cell.content) }; | ||
if (i.contains(cell.y) and j.contains(cell.x)) { cell.content = { set text(red); cell.content } }; | ||
let i = (3,); | ||
let j = (0,1,2,); | ||
|
||
if (i.contains(cell.y) and j.contains(cell.x)) { cell.content = strong(cell.content) }; | ||
if (i.contains(cell.y) and j.contains(cell.x)) { cell.content = strike(cell.content) }; | ||
if (i.contains(cell.y) and j.contains(cell.x)) { cell.fill = black }; | ||
if (i.contains(cell.y) and j.contains(cell.x)) { cell.content = { set text(white); cell.content } }; | ||
|
||
if (cell.x == 0) { cell.align = left }; | ||
if (cell.x == 1) { cell.align = center }; | ||
if (cell.x == 2) { cell.align = center }; | ||
if (cell.x == 3) { cell.align = center }; | ||
if (cell.x == 4) { cell.align = right }; | ||
// tinytable cell style before | ||
return cell; | ||
}, | ||
|
||
// tinytable cell content after | ||
colspanx(1, align: center)[ ],colspanx(2, align: center)[Group 2],colspanx(2, align: center)[Group 1], | ||
[mpg], [cyl], [disp], [hp], [drat], | ||
[21], [6], [160], [110], [3.9], | ||
[21], [6], [160], [110], [3.9], | ||
[22.8], [4], [108], [93], [3.85], | ||
[21.4], [6], [258], [110], [3.08], | ||
|
||
|
||
) // end tablex | ||
) // end figure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
source("helpers.R") | ||
using("tinysnapshot") | ||
options(tinytable_print_output = "typst") | ||
|
||
|
||
|
||
# semi complicated | ||
tab <- tt(mtcars[1:4, 1:5], caption = "Hello World") |> | ||
group_tt(j = list("Group 1" = 4:5, "Group 2" = 2:3)) |> | ||
style_tt(j = 1:5, align = "lcccr") |> | ||
style_tt(i = 2, j = 1:3, strikeout = TRUE, bold = TRUE, background = "black", color = "white") |> | ||
style_tt(j = 1, color = "red", italic = TRUE) | ||
expect_snapshot_print(tab, label = "typst-complicated") | ||
|
||
|
||
|
||
|
||
options(tinytable_print_output = NULL) |