#Gap between two `table.hline()`

20 messages · Page 1 of 1 (latest)

wicked flax
#

Hi all,

I'm drawing a table and want to add spanning column labels with a "partial" rule under. What I need is similar to what \cmidrule does in LaTeX: lines under the spanning column label, with gaps between the lines to keep them distinct.

When I use two table.hline() side by side, they connect into a continuous line. Is there a way to insert a small gap between them so they show up as distinct? Using #tablex, I would use the expand argument with a negative value, but I need to use the built-in table functionality in Typst rather than an external package.

Any ideas would be much appreciated!

Here's a minimal example, a screenshot of the result, and an example of what I'm trying to replicate in LaTeX:

#table(
  columns: 5,
  stroke: none,
  [], table.cell(colspan: 2, align: center)[bc], table.cell(colspan: 2, align: center)[de],
  [a], [b], [c], [d], [e],
  [1], [2], [3], [4], [5],
  table.hline(y: 1, start: 1, end: 3),
  table.hline(y: 1, start: 3, end: 6),
)
wind spoke
#

Use per-cell bottom stroke instead of hlines

#

The top line, The line below A B (middle line)and the line at the bottom would be full-width hlines

#

The line below I would be table.cell(stroke: (bottom: black), colspan: 2)[I]

#

Same for the one below II

#

And finally, to have separation between the two, you'd use column-gutter: 3pt for example

wicked flax
#

Wow, this is amazing. Works perfect. Thanks so much for taking the time to answer my newbie questions! I really appreciate it.

wind spoke
#

The tables guide in the Typst docs has very useful info here, but I'm afraid it doesn't cover this specific use case yet

#

Might be a good addition to have however

wicked flax
#

Yeah. I do think I should have been able to figure this out from the docs, but I'm still not familiar enough with basic typst syntax. I agree it is a reasonably important use case and could be documented. One (very) minor issue with column-gutter is it applies everywhere, so the table looks off if there's fill. I suppose we could color the gutter too, but the fill might be row-specific.

#

But as I said, this is a very minor issue.

wind spoke
wicked flax
#

ooooh, that's nice!

wind spoke
#

with that said, fill still only applies to cells

#

for a table-wide fill, you can use #block(fill: red, table(...)) for example

wicked flax
#

Oh, I didn't know that. That's a really interesting feature.

wind spoke
#

wow, nice!

#

feel free to ping me if u need feedback