PgBiel/typst-tablex

Colspan over 1fr prompting auto columns to needlessly expand

PgBiel opened this issue · 3 comments

PgBiel commented

The "BC" column should have the same width in both samples.
image

#tablex(
    columns: (auto, auto, 1fr),
    [A], [BC], [D],
    [A], [BC], [D],
    [A], [BC], [D],
    [A], [BC], [D]
)

#tablex(
    columns: (auto, auto, 1fr),
    colspanx(3)[Hello world! Hello!],
    [A], [BC], [D],
    [A], [BC], [D],
    [A], [BC], [D],
    [A], [BC], [D]
)
PgBiel commented

Fixing this is a bit harder than it may seem - a colspan may span a fractional column which does not span all the available space (e.g. if there are two 1fr columns: each will take half of the available space). Such a case would require some form of two-pass algorithm.

With fit-spans: (x: true), this problem can now be manually solved.

#tablex(
    columns: (auto, auto, 1fr),
    fit-spans: (x: true),
    colspanx(3)[Hello world! Hello!],
    [A], [BC], [D],
    [A], [BC], [D],
    [A], [BC], [D],
    [A], [BC], [D]
)

second column has the normal width now

Keeping this open so I can make tablex smarter in the future, in case the cell spans all fractional columns.

This particular case (of a cell spanning all frac columns) is now automatically handled. For other cases, the fit-spans: (x: true) option must be used to opt into having auto columns ignore colspans.