A Typst library for writing simple tables.
Usage
#import "@preview/easytable:0.1.0": easytable, elem
#import elem: *
Manual
- You can create a table by specifying data or layout elements as arguments to the
easytable
function. - The following elements are provided in the
elem
module.elem.tr
: a data rowelem.th
: a header rowelem.hline
: a horizontal lineelem.vline
: a vertical lineelem.cwidth
: a column-width specifierelem.cstyle
: a column-style (font, alignment, etc.) specifier
See manual in detail.
Examples
A Simple Table
#easytable({
th[Header 1 ][Header 2][Header 3 ]
tr[How ][I ][want ]
tr[a ][drink, ][alcoholic ]
tr[of ][course, ][after ]
tr[the ][heavy ][lectures ]
tr[involving][quantum ][mechanics.]
})
Setting Column Alignment and Width
#easytable({
cwidth(100pt, 1fr, 20%)
cstyle(left, center, right)
th[Header 1 ][Header 2][Header 3 ]
tr[How ][I ][want ]
tr[a ][drink, ][alcoholic ]
tr[of ][course, ][after ]
tr[the ][heavy ][lectures ]
tr[involving][quantum ][mechanics.]
})
Customizing Styles
#easytable({
let tr = tr.with(trans: pad.with(x: 3pt))
th[Header 1][Header 2][Header 3]
tr[How][I][want]
tr[a][drink,][alcoholic]
tr[of][course,][after]
tr[the][heavy][lectures]
tr[involving][quantum][mechanics.]
})
#easytable({
let th = th.with(trans: emph)
let tr = tr.with(
cell_style: (x: none, y: none)
=> (fill: if calc.even(y) {
luma(95%)
} else {
none
})
)
th[Header 1][Header 2][Header 3]
tr[How][I][want]
tr[a][drink,][alcoholic]
tr[of][course,][after]
tr[the][heavy][lectures]
tr[involving][quantum][mechanics.]
})
#easytable({
th[Header 1][Header 2][Header 3]
tr[How][I][want]
hline(stroke: red)
tr[a][drink,][alcoholic]
tr[of][course,][after]
tr[the][heavy][lectures]
tr[involving][quantum][mechanics.]
// Specifying the insertion point directly
hline(stroke: 2pt + green, y: 4)
vline(
stroke: (paint: blue, thickness: 1pt, dash: "dashed"),
x: 2,
start: 1,
end: 5,
)
})