PgBiel / typst-tablex

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

Colspan over 1fr prompting auto columns to needlessly expand #56

Closed PgBiel closed 8 months ago

PgBiel commented 1 year ago

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 1 year ago

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.

PgBiel commented 8 months ago

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.

PgBiel commented 8 months ago

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.