4

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}

Top

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}

Bottom

Anyone know how to work this?

4

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*{.89\textheight}% this page
% \vspace*{.90\textheight}% next page

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

\end{document}
|improve this answer|||||
  • Yep, definitely simpler... I blame David for teaching me to not read documentation. :-) – Peter Grill May 17 '13 at 8:09
  • 2
    @PeterGrill :) I didn't read it either - I simply happened to remember the optional argument... – cgnieder May 17 '13 at 8:10
3

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}
|improve this answer|||||
1

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}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.