Is there a way to automatically determine the page height for balanced two-column page?

#set page(height: auto) can make typst automatically determine the proper height to display all the stuffs in one page, like:

#set page(height: auto, width: 4.5in)
#lorem(100)

But now I want to use height: auto option for two columns page, and this is how it looks like:

#set page(height: auto, width: 4.5in, columns: 2)
#lorem(50)

or

#set page(height: auto, width: 4.5in)
#columns(2)[#lorem(150)]


All the content is on the one side, and the other side is left blank, which is not that good.

What I want is something like:


i.e. two columns are balanced and just fit in one page.

At first, I tried to use measure to get the height of all content and set the page height to half of it, but there are spacing between two columns, so the height is not always (maybe always not) that exact, even if I did some experiments and got a relatively good coefficient rather than simply using 1/2 to calculate the height for two columns from the original height.

Another idea is to detect whether a page is enough for the content and iterate several times to find the critical point and finally get a tight bound for height, but this may be of low efficiency and may encounter layout did not converge within 5 attempts if doing this inside the typst document.

So what is the best practice for making a one page two columns document, or is that possible?

I am new to this community and not proficient in typst and English, and I’ve already searched the web and this forum for something relevant but in vain. I would appreciate it if you could offer any help, thanks in advance.

P.S. I need to do so as I am currently working with an automatic publishing system for campus news & information. We previously found out that this form may be the best for phone readers, and we could manually adjust the geometry for LaTeX document everyday in the past.

There is currently no proper way to do this, but there is an open issue on GitHub for balancing the columns, and I believe this would then also allow for auto page height. In that issue people have posted several workarounds which could be helpful for your use case. Here the link:

2 Likes

The eqcolumns workaround provided by @dahooz in issue 466 seems to perfectly resolve my problem. Thank you for the instruction!

Update: Sometimes eqcolumns will underestimate the height needed, like:


Especially some layout rules are applied to add some space.
I suggest to add some extra space in the parameter height passed to block. Basically, + 0.3 em to + 0.6 em at 12pt font size will be enough for most circumstances.