Consider the table below. When we measure its width, it is returning as 250pt which is clearly incorrect. Since the table is the full width of the page, with 1fr for the middle column it should be returning 400pt for it’s width (500 - 2 x 50 margin). This is clear in the second table, where we have fixed widths for all columns and have replaced 1fr with 150pt literal and it returns 400pt as expected.
How can we have determine the width of tables with fractional columns?
measure, by default, will measure whatever you pass to it assuming it is placed inside a container of infinite size. if you don’t want that behavior, you’ll have to pass it the dimensions of the desired parent container, like measure(width: w, height: h, thing). given that, we can caclulate that for example something with width 50% would end up with width 100pt when its parent has width 200pt.
but how do we get the dimensions of our parent container? with layout! this function first produces a block (which must end up in the output), then it measures this block’s parent, and then it passes this result to the function that you specify (=>), whose result will be placed inside this block. this is why it’s important to place your layout call outside of the list, or otherwise you would be measuring the table as if it was placed inside this list. instead ,you wanna place it at the page level (so that our parent is the whole page). the end result gives you something like this:
table 1
table 2
contextless measurement
250pt
400pt
layouted measurement
400pt
400pt
this checks out on all fronts. now you might be wondering why the first table’s contextless measurement still gives 250pt. first, remember that its columns’ widths are defined as 100pt, 1fr, 150pt. again, contextless measurements are layouted in an infinitely large container. so 1fr, a size that is a fraction of infinity, is also infinity! this gets returned as 0pt (you can test this by measuring a rect(width: 10%)), which when added with the other two absolute values, results in 250pt. i guess you can think of it as a “min-width” measurement.