PgBiel / typst-tablex

More powerful and customizable tables in Typst
MIT License
370 stars 12 forks source link

Create `fit-spans` option #111

Closed PgBiel closed 7 months ago

PgBiel commented 8 months ago

Helps with (potentially closes) #56 and #78.

The idea is to be able to specify #tablex(fit-spans: (y: true)) in order to have colspans not affect auto columns' sizes. That way, fractional columns won't be "squashed".

Consider the table below, from #78:

#tablex(
    columns: (1fr, 1fr, auto, auto, auto),
    [a], [b], [c], [d], [e],
    cellx(colspan: 5)[#lorem(5)],
    [a], [b], [c], [d], [e],
    cellx(colspan: 2)[#lorem(10)], none, none, none,
    [a], [b], [c], [d], [e],
    cellx(colspan: 3)[#lorem(15)], none, none,
)

The last row has a colspan which spans not only the two fractional columns, but also one auto column, causing the latter to expand more than it should (since auto columns are measured before fractional columns), leading to zero-width fractional columns:

The first, second and third columns are overlapping

Adding fit-spans: (x: true) causes the auto column to ignore the colspan's size, fixing the problem:

The three first columns are not overlapping anymore