I'm formatting a document using the multicol
package. As I in some parts have frequent short subsections I ideally would not want them to be "column broken" such that the subsection heading and all of its text always appears in the same column. This can of course be done by a minipage
environment as in Unbreakable block.
However, when using that environment and therefore causing a, lets call it premature, columnbreak before a longer section, lots of white space is added in between all line breaks of the preceding section. I would like to avoid this and have the content of the preceding column all be stacked on the top, as usual.
Using a minipage
environment with [t]
specified did not help my problem unfortunately, neither did a samepage
environment. I also was not able to find anything specific to this in the package manual of multicol
, however I think that there should probably be a solution to this also when using just normal pages and page breaking before longer sections instead of column breaking (I was not sure whether this would then work in a multicol environment though, so I added that extra information in this question).
In case you're confused, here is a MWE that hopefully clears things up:
\documentclass[10pt]{article}
\usepackage{multicol}
\usepackage{lipsum}
\begin{document}
\newbox\one
\newbox\two
\long\def\loremlines#1{%
\setbox\one=\vbox {%
\lipsum%
}
\setbox\two=\vsplit\one to #1\baselineskip
\unvbox\two}
\begin{multicols*}{2}
\section*{Section 1}
So this is a section that I would like to be on the left column. Let me add some text here.
Here is some text.
\smallskip
\loremlines{10}
\section*{Section 2}
This is also a section that still fits onto the left column so lets leave it here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\section*{Section 3}
This is a section that starts on the left column and continues on the right. As the sections in my document are usually much smaller than this, I would not want this, and would rather have the section heading on the right column, along with all of its text.
Here is some text.
\smallskip
\loremlines{18}
On the next page I will show what I would not want to happen (using one minipage; and then on the following page one using three minipages).
\end{multicols*}
\clearpage
\begin{multicols*}{2}
\section*{Section 1}
So this is a section that I would like to be on the left column. Let me add some text here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\section*{Section 2}
This is also a section that still fits onto the left column so lets leave it here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\begin{minipage}[t]{0.48\textwidth}
\section*{Section 3}
This is a section that used to start on the left column and continued on the right. Now it is completely on the right (yay!) but look at the left side. What a mess! (is even worse when there are three or four really short sections on the left, and this section originally took quite a big part of the left column).
Here is some text.
\smallskip
\loremlines{18}
\end{minipage}
\end{multicols*}
\clearpage
\begin{multicols*}{2}
\begin{minipage}[t]{0.48\textwidth}
\section*{Section 1}
So this is a section that I would like to be on the left column. Let me add some text here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\end{minipage}
%the space here should go poof! else this looks fine.
\begin{minipage}[t]{0.48\textwidth}
\section*{Section 2}
This is also a section that still fits onto the left column so lets leave it here.
Here is some text.
And here some more.
\smallskip
\loremlines{10}
\end{minipage}
\begin{minipage}[t]{0.48\textwidth}
\section*{Section 3}
So the left side looks better than before. But still not really appealing. The space between the two sections on the left side should ideally go 'poof'.
Here is some text.
\smallskip
\loremlines{18}
\end{minipage}
\end{multicols*}
\end{document}
(definition of loremlines
taken from Is there an equivalent of lipsum for shorter sections of text? and minimally adapted)
Thanks a lot!
Update: As Ivan has pointed out in a comment, I could add \vfill\null
to manually force space to disappear. I'm wondering whether there is a possibility of not needing to do anything manually (adding \vfill\null
after each minipage does not do anything of course) after compiling.
\vfill\null
before the lastminipage
on page 2 solve your problem?