Closed manveru closed 7 months ago
Related: #56
I believe this happens because auto
columns are calculated before fr
columns. As such, the last lorem paragraph expands the most it can, causing the auto
column to take all available space, leaving 0 space for the 1fr
columns. I'd like to improve the handling of 1fr
columns in such cases, but this is complicated because, technical limitations aside, I'm not sure what the expected behavior should even be! :joy:
I guess one could consider splitting evenly between auto
and 1fr
in such cases, but that'll need further thought.
My intuition about this was that auto
takes at least the width of the widest word within that column, while fractions take up the remaining space. But this is obviously very subjective.
So maybe additional options would be a better way to express that?
I'm imagining something like:
wide
: Don't allow any additional line breaks within cells of that column, make the column as wide as the widest container across all rows.break
: Allow for line and maybe even word breaks, and make the column as wide as required for that.no-break
: Make the column wide enough so no additional breaks have to be introduced within cells.I have no idea how complicated the calculations for each of these would be, I'm mostly trying to achieve the same effect as you'd get when auto-sizing a column in a spreadsheet application for now.
Thanks for the input. I believe your ideas are in the right direction.
I've found that tabularray[^1] has an option which would be the equivalent in tablex of having colspans not affect the sizes of auto columns at all (or rowspans not affect the sizes of auto rows). With such an option, you'd force colspans to fit into existing columns instead of causing them to expand, which would solve your problem, as the auto
column it spans wouldn't expand unnecessarily. Of course, however, the colspan would have less space available, but that's a tradeoff one must consider. You'd choose what looks best in the end.
That could thus be added to tablex in an attempt to alleviate this kind of problem if needed.
Another solution, of course, is replacing the auto
column by a fixed width column, but that's not always very convenient.
[^1]: Starting at p. 27 of tabularray docs (hspan
etc. options): https://mirrors.ctan.org/macros/latex/contrib/tabularray/tabularray.pdf
You may now (once v0.0.8 releases) use fit-spans: (x: true)
to solve your problem. It causes auto columns to ignore colspans:
#tablex(
columns: (1fr, 1fr, auto, auto, auto),
fit-spans: (x: true),
[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,
)
Keeping this open as I might make tablex smarter in this regard in the future (specifically if the cell spans all fractional columns available).
This particular case (of a colspan over all fractional columns) is now automatically handled. You may opt into having auto columns ignore the sizes of colspans with fit-spans: (x: true)
.
Here's a rendered version of the difference the last row makes:
It seems like some combination of longer text with automatic sizing and fractional scaling may cause that, but I can't really figure out the logic behind this.