Is there any simple way of creating a three-line table like Latex?

In Latex, a three-line table can be created by \toprule, \midrule and \bottomrule. Is there any similar solution in Typst?

1 Like

Sure. If you look at the documentation of the booktab package for LaTeX, you will find these two lengths:

\heavyrulewidth=.08em
\lightrulewidth=.05em

So we can use them to mimic the booktab look, like this:

#import "@preview/metalogo:1.0.2": TeX, LaTeX

#set table(stroke: none)

#let toprule = table.hline(stroke: 0.08em)
#let bottomrule = toprule
#let midrule = table.hline(stroke: 0.05em)

#table(
  columns: 2,
  toprule,
  table.header(
    [Name],
    [Made public]
  ),
  midrule,
  [Typst], [2023],
  LaTeX, [1984],
  TeX, [1978],
  bottomrule
)

a

3 Likes

Thank you very much!

Thanks a lot for your answer. How can I make a “three-line table” template or somethings, while there are a lot of tables in a document, and it’s kind of tiring to write “toprule”/“midrule”/“bottomrule” in every table instance.

You can create a function that does this for you. This example takes a list of values as its only argument:

#import "@preview/metalogo:1.0.2": TeX, LaTeX

#let three-line-table(cells) = {
  let toprule = table.hline(stroke: 0.08em)
  let bottomrule = toprule
  let midrule = table.hline(stroke: 0.05em)
  table(
    columns: 2,
    stroke: none,
    toprule,
    table.header(..cells.slice(0, count: 2)),
    midrule,
    ..cells.slice(2),
    bottomrule
  )
}

#three-line-table(
  (
    [Name], [Made public],
    [Typst], [2023],
    LaTeX, [1984],
    TeX, [1978],
  )
)
Result

image