TypstUniverse

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 row
    • elem.th: a header row
    • elem.hline: a horizontal line
    • elem.vline: a vertical line
    • elem.cwidth: a column-width specifier
    • elem.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.]
})

image

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.]
})

image

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.]
})

image

#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.]
})

image

#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,
  )
})

image