Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

LaTeX: Prevent verbatim text being broken across pages

📅 2012-Dec-21 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Problem

LaTeX might break a long stretch of verbatim text across two or more pages.

Solution

To restrict all the text in a verbatim environment to a single page, use the fancyvrb package. Switch to using the Verbatim environment (note the uppercase V) and set the samepage parameter to true.

Here is an illustration:

\usepackage{fancyvrb}

% ...

\begin{Verbatim}[samepage=true]
A
stretch
of
text
you
want
to
remain
on
a
single
page
\end{Verbatim}

Tried with: MikTeX 2.9 and Windows 8 Pro x64