[Tex/LaTex] how to make ragged bottoms of columns in multicols when preventing page breaks

multicolsectioning

The setup: I need to use multicols for say 3 columns where I have many small sections. I noticed that some sections are broken in the middle and end up wrapping to the next column, which I do not want.

After some research (i.e googling) found that adding \interlinepenalty=10000 prevents this. And it does. Multicol – don't wrap

But instead of having the gaps at the bottom of the columns (ragged bottoms, or whatever the correct name for it), the columns end up with large empty space in between, which does not look good.

Mathematica graphics

generated using:

\documentclass[10pt,notitlepage]{article}%
\setlength{\columnseprule}{0pt} %column thicnkess 
\setlength{\columnsep}{5.0pt}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage{titlesec}
\titleformat{\section}{\large\bfseries}{\thesection}{1em}{}
\begin{document}
\begin{multicols*}{3}     
\interlinepenalty=10000
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[3]
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[4]
\section{some section}
\lipsum[75]
\end{multicols*}
\end{document}

removing \interlinepenalty=10000 gives

Mathematica graphics

which I do not want since section is flowing across columns.

Removing the star version does not help either. One must use \interlinepenalty=10000 to prevent page break inside a section. But then the problem are those large gaps in between sections.

Then I used samepage to wrap each section inside it in the hope it will help. But this result was more strange. I must have done something wrong here:

Mathematica graphics

Here is the code for the above

\documentclass[10pt,notitlepage]{article}%
\setlength{\columnseprule}{0pt} %column thicnkess 
\setlength{\columnsep}{5.0pt}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage{titlesec}
\titleformat{\section}{\large\bfseries}{\thesection}{1em}{}
\begin{document}
\begin{multicols}{3}     
%\interlinepenalty=10000

\begin{samepage}
\section{some section}
\lipsum[75]
\end{samepage}

\begin{samepage}
\section{some section}
\lipsum[75]
\end{samepage}

\begin{samepage}
\section{some section}
\lipsum[3]
\end{samepage}

\begin{samepage}
\section{some section}
\lipsum[75]
\end{samepage}

\begin{samepage}
\section{some section}
\lipsum[75]
\end{samepage}

\begin{samepage}
\section{some section}
\lipsum[75]
\end{samepage}

\begin{samepage}
\section{some section}
\lipsum[4]
\end{samepage}

\begin{samepage}
\section{some section}
\lipsum[75]
\end{samepage}

\end{multicols}
\end{document}

What is the correct way to prevent page breaks in the middle of sections, but have the extra space be at the bottom and not in between?

Using Tex live 2013 on Linux. (ps. one day, I need to learn how to use Latex to make copies code fragment to I do not copy paste same code again and again).

Best Answer

The desired effect can be achieved using the \raggedcolumns macro:

\documentclass[10pt,notitlepage]{article}%
\setlength{\columnseprule}{0pt} %column thicnkess 
\setlength{\columnsep}{5.0pt}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage{titlesec}
\titleformat{\section}{\large\bfseries}{\thesection}{1em}{}
\begin{document}
\begin{multicols}{3}
\raggedcolumns     %new code
\interlinepenalty=10000
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[3]
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[75]
\section{some section}
\lipsum[4]
\section{some section}
\lipsum[75]
\end{multicols}
\end{document}

enter image description here