Skip to content

Instantly share code, notes, and snippets.

@te-lang-wakker
Last active April 12, 2023 19:14
Show Gist options
  • Save te-lang-wakker/1382d9df802ceb865475f2feae756429 to your computer and use it in GitHub Desktop.
Save te-lang-wakker/1382d9df802ceb865475f2feae756429 to your computer and use it in GitHub Desktop.
#import "tablex.typ": *
#let groupedx(data, results-start: none, gutter: auto, column-gutter: auto, row-gutter: auto, fill: none, align: horizon, stroke: black, inset: 5pt) = {
let datax = data.map(x => x.map(y => ()))
let number-of-columns = data.at(0).len()
let number-of-rows = data.len()
let skip = ()
for row in range(number-of-rows) {
for column in range(number-of-columns) {
if skip.find(it => it.at(0) == column and it.at(1) == row) != none {
continue
}
let entry = data.at(row).at(column)
let xspan = 1
let yspan = 1
if results-start == none or column < results-start.at(0) {
while column + xspan < number-of-columns and data.at(row).at(column + xspan) == entry {
xspan += 1
}
while row + yspan < number-of-rows and data.at(row + yspan).at(column) == entry {
yspan += 1
}
for x in range(xspan) {
for y in range(yspan) {
skip.push((column + x, row + y))
}
}
}
datax.at(row).at(column) = cellx(
colspan: xspan,
rowspan: yspan
)[
#if results-start != none and (column < results-start.at(0) or row < results-start.at(1)) {
text(weight: "bold", entry)
}
else {
entry
}
]
}
}
tablex(
columns: number-of-columns,
rows: number-of-rows,
gutter: gutter,
row-gutter: row-gutter,
fill: fill,
align: align,
stroke: stroke,
inset: inset,
..datax.flatten()
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment