Красивый перенос таблиц
This commit is contained in:
@@ -5,16 +5,76 @@
|
||||
|
||||
#let pz-appendix-title(body) = heading(level: 1)[#body]
|
||||
|
||||
#let pz-table(caption, columns, ..body) = figure(
|
||||
#let pz-column-count(columns) = if type(columns) == int {
|
||||
columns
|
||||
} else if type(columns) == array {
|
||||
columns.len()
|
||||
} else {
|
||||
1
|
||||
}
|
||||
|
||||
// Строка из ..range().map(i => ([a], [b])) в body.pos() — один аргумент-массив.
|
||||
#let pz-flatten-cells(cells) = cells.fold((), (acc, cell) => {
|
||||
if type(cell) == array { acc + cell } else { acc + (cell,) }
|
||||
})
|
||||
|
||||
#let pz-table-inner(columns, header-cells, tab-num, start-page, ..rows) = {
|
||||
let col-n = pz-column-count(columns)
|
||||
let cont-cell = table.cell(
|
||||
colspan: col-n,
|
||||
stroke: none,
|
||||
inset: (x: 0pt, y: 2pt),
|
||||
align: left,
|
||||
)[
|
||||
#context {
|
||||
if start-page.get() == none {
|
||||
start-page.update(here().page())
|
||||
}
|
||||
let first-page = start-page.get()
|
||||
if first-page != none and here().page() > first-page {
|
||||
[Продолжение таблицы #tab-num]
|
||||
}
|
||||
}
|
||||
]
|
||||
let header-row = if header-cells.len() > 0 {
|
||||
(cont-cell, ..header-cells)
|
||||
} else {
|
||||
(cont-cell,)
|
||||
}
|
||||
table(
|
||||
columns: columns,
|
||||
..body,
|
||||
),
|
||||
table.header(..header-row),
|
||||
..rows,
|
||||
)
|
||||
}
|
||||
|
||||
#let pz-table(caption, columns, ..body) = {
|
||||
let pos = body.pos()
|
||||
let has-header = pos.len() > 0 and pos.first().func() == table.header
|
||||
let header-cells = if has-header { pos.first().children } else { () }
|
||||
let tail = pz-flatten-cells(if has-header { pos.slice(1) } else { pos })
|
||||
let start-page = state("pz-table-start-page", none)
|
||||
figure(
|
||||
kind: table,
|
||||
context {
|
||||
let fig-loc = here()
|
||||
let tab-num = counter(figure.where(kind: table)).at(fig-loc).first()
|
||||
start-page.update(none)
|
||||
pz-table-inner(columns, header-cells, tab-num, start-page, ..arguments(..tail))
|
||||
},
|
||||
caption: caption,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Реестры unit-тестов: перенос длинных идентификаторов (camelCase, _); сетка как в примере Typst.
|
||||
#let pz-test-table(caption, columns, ..body) = figure(
|
||||
#let pz-test-table(caption, columns, ..body) = {
|
||||
let pos = body.pos()
|
||||
let has-header = pos.len() > 0 and pos.first().func() == table.header
|
||||
let header-cells = if has-header { pos.first().children } else { () }
|
||||
let tail = pz-flatten-cells(if has-header { pos.slice(1) } else { pos })
|
||||
let start-page = state("pz-table-start-page", none)
|
||||
figure(
|
||||
kind: table,
|
||||
{
|
||||
show table: set text(hyphenate: true, size: 9pt)
|
||||
show table.cell: cell => {
|
||||
@@ -24,13 +84,16 @@
|
||||
show regex("[_]"): it => it + sym.zws
|
||||
cell
|
||||
}
|
||||
table(
|
||||
columns: columns,
|
||||
..body,
|
||||
)
|
||||
context {
|
||||
let fig-loc = here()
|
||||
let tab-num = counter(figure.where(kind: table)).at(fig-loc).first()
|
||||
start-page.update(none)
|
||||
pz-table-inner(columns, header-cells, tab-num, start-page, ..arguments(..tail))
|
||||
}
|
||||
},
|
||||
caption: caption,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
#let pz-fig(path, caption, lbl) = [
|
||||
#figure(
|
||||
|
||||
Reference in New Issue
Block a user