But this makes the rectangle have the width of the entire text line and thus it overflows the page. How can I give the size of the rest of the line that is not already covered with the heading text?
The problem with using stack is that it currently doesnât change the meaning of 100% when some space is already occupied by previous children, so the width of the rectangle is that of the full page (minus the margins).
What you can do instead is to use a grid, which translates very easily:
When using a grid, I would recommend setting the columns to (auto, 1fr). Otherwise, the second column will compete with the heading for space, which will become noticeable once the heading itself takes up more than half the page.
Alternatively, but this would involve rewriting the whole heading show rule from scratch, one could use an 1fr width box.
What does this mean? I understand something like (1fr, 2fr) as first column takes up 1/3 of the parent second column takes up 2/3 of the parent. Does (auto, 1fr) mean that the first column takes up just as much space as the child wants (heading text in this case) and that the second column takes up 1/1 of the remaining space? I guess thatâs what it means, because (auto, 2fr) seems to have the same effect. So does auto then take precedence and the fractions just get to divie up the rest of the available space?
The documentation for grid explains it well. It doesnât explain what the mentioned âtracksâ are but I guess it means columns, rows maybe even the gutters.
auto: The track will be sized to fit its contents. It will be at most as large as the remaining space. If there is more than one auto track width, and together they claim more than the available space, the auto tracks will fairly distribute the available space among themselves.
A fixed or relative length (e.g. 10pt or 20% - 1cm): The track will be exactly of this size.
A fractional length (e.g. 1fr): Once all other tracks have been sized, the remaining space will be divided among the fractional tracks according to their fractions. For example, if there are two fractional tracks, each with a fraction of 1fr, they will each take up half of the remaining space.