# Same page and multicols

I use multicols at times for specific blocks in my thesis, which has a title, and a block of stuff similar to the following:

\documentclass{article}

\usepackage{lipsum}
\usepackage{multicol}

\newenvironment{mh}[1]{%
\textbf{#1}%
\begin{multicols}{2}%
}{%BODY
\end{multicols}%
}

\begin{document}
\begin{mh}{This is the title.}
\lipsum[1]
\end{mh}
\end{document}


I am getting an occurrence which is creating a page break between the title and the body, so I need to be able to instruct them to be on the same page. However the problem is, that using begin{samepage} ... \end{samepage} destroys the multicols environment, putting all the text in one column as per below:

 %NEED TO FORCE HEADING AND BLOCK ON SAME PAGE
\begin{samepage}
\begin{mh}{This is the title.}
\lipsum[1]
\end{mh}
\end{samepage}


Anyone know how to work this?

The simplest way: use the optional argument that the {multicols} environment has for exactly such purposes:

\documentclass{article}

\usepackage{lipsum}
\usepackage{multicol}

\newenvironment{mh}[1]{%
\begin{multicols}{2}[\textbf{#1}]%
}{%BODY
\end{multicols}%
}

\begin{document}

% \vspace*{.90\textheight}% next page

\begin{mh}{This is the title.}
\lipsum[1]
\end{mh}

\end{document}

• Yep, definitely simpler... I blame David for teaching me to not read documentation. :-) May 17 '13 at 8:09
• @PeterGrill :) I didn't read it either - I simply happened to remember the optional argument... May 17 '13 at 8:10

You can use the needspace package to add a new page if there is not enough space for both the title and the content.

## Note:

• It would be better to provide MWE that actually reproduces the problem (as the one below does if you comment out the \needspace{3\baselineskip}.

• The MWE below will keep three lines together on the page, otherwise will go to a new page. If you prefer to keep a few more lines with the section heading you can increase the factor 3 to a larger number.

## Code:

\documentclass{article}
\usepackage{needspace}

\usepackage{lipsum}
\usepackage{multicol}

\newenvironment{mh}[1]{%
\needspace{3\baselineskip}%
\textbf{#1}%
\begin{multicols}{2}%
}{%BODY
\end{multicols}%
}

\begin{document}
\lipsum[1-5]
\begin{mh}{This is the title.}
\lipsum[1]
\end{mh}
\end{document}


You can use a minipage environment instead:

\documentclass{article}

\usepackage{lipsum}
\usepackage{multicol}

\newenvironment{mh}[1]{%
\textbf{#1}%
\begin{multicols}{2}%
}{%BODY
\end{multicols}%
}

\begin{document}

\begin{minipage}{\linewidth}
\begin{mh}{This is the title.}
\lipsum[1]
\end{mh}
\end{minipage}

\end{document}

• But it spoils indentation. May 17 '13 at 2:16