I saw a post on Reddit earlier today in which it was brought to my attention that Typst does not yet have out-of-the-box support for "balanced columns". Behold, I have implemented it! Just wrap a columns(...) in make_balanced() (or do #show columns: element=>make_balanced(element) to affect all columns(...) objects within the current scope) and the columns will be confined to a box(...) that sets its height such that all columns will have a (roughly) equal amount of content!
It works in 5 simple steps:
- Based on the desired number of columns and the available width (of the page or other parent container) as well as the gutter width (supports relative and absolute forms!), determine how wide each column will be. This of course assumes that the columns will be of equal width.
- For each content item, hypothetically lay out the item in a box whose width is equal to the individual column width. Record the resulting element heights.
- The sum of these heights (and potential paragraph breaks between items) is the total content height.
- Divide the content height by the number of columns to get the "target height" for a column (and thus for the entire
columns(...)object). - Set the outer box's height to this "target height" value.