A common solution is to use \begin{samepage}...\end{samepage}; however, in my case this won't work as this is a multi-page listing.
For now I'm putting a \begin{verbatim}...\end{verbatim} inside the \begin{largecodesample} in the doc. How can I get LaTeX to prefer to do a page break inside the Verbatim environment, but not between Verbatim and the caption?
This is what I have. You can see how I get desperate with all the \nopagebreak...
Thanks
Code: Select all
\newenvironment{largecodesample}[1]%
{
\stepcounter{CodeSampleCounter}
\global\def\codetitle{#1}
\global\def\mytitle{Code Sample \arabic{CodeSampleCounter}{}: {#1}}
\begin{shaded}
\renewcommand\label[1]{\@bsphack
\protected@write\@auxout{}%
{\string\newlabel{##1}{{\arabic{CodeSampleCounter}}{\thepage}}}%
\@esphack}
}
{\nopagebreak
\end{shaded}
\nopagebreak
\begin{center}
\nopagebreak
\textbf{\mytitle}
\end{center}
\addtocontents{spl}{\protect\contentsline {subsection}%
{\mytitle\relax}{\thepage}}
}