Background
Creating books automatically using LaTeX-escaped user-generated content.
Problem
The book layouts make use of the multi-column package, with the book content separated into sections. If the second section is too long, is written entirely on the subsequent page, regardless of how much space remains after the first section.
Question
How do you force the multicols
package to only break to the next column while in the first column, but to not break if within the second column?
Output
The following figure illustrates the intent of the question; the second section should fill as much space in the second column of the first page as possible; overflowing to the second page whatever portion of the second section that does not fit:
Code
A minimal example to recreate the issue:
\documentclass{article}
\usepackage{lipsum}
\usepackage{multicol}
\raggedcolumns
\begin{document}
\begin{multicols*}{2}
\section{First}
\lipsum[1-3]
% Insert column break ONLY IF still within 1st column (e.g. if \lipsum[1-2] above).
% DO NOT insert column break if already in 2nd column (e.g. if \lipsum[1-3] above).
\columnbreak
\section{Second}
\lipsum[4-5]
\end{multicols*}
\end{document}
Attempts
I've tried using multicols*
and \raggedcolumns
to no avail. I thought that \maxbalancingoverflow
would help, but could not get it to parse.
Related
Questions I found useful, but did not offer any simple solutions:
Best Answer
The answer in the related question Detecting current column in multicol should have solved the problem since it was written to detect in which column you are. So my first guess was that
should do the trick.
Unfortunately it doesn't, because the way I had written
\docolaction
the point that determines in which column we are is the point directly following the executed argument. So executing\columnbreak
above would shift it from the first to the second column :-( As there are cases where it is correct to have this order one can't really say that it is wrong as implemented.So either one needs to redefine
\docolaction
or do a little bit or reprogramming like this:Implemented like this it also works with 3 or more columns. E.g. using
\lipsum[1-3]
we getAnd with
\lipsum[1-2]
a column break happens:Of course, this code also works with a different number of columns including 2 as as in the OP question. I only gae the example of 3 columns to show that it is not restricted to the two-column situation and can make use of
multicol
s ability to produce more columns.For reference here is the full code using the
mccolaction
package (in a version that works with the development version in SVN and the CTAN version of multicol):