3

I have a portion of code that is larger than page. I use following lstlisting configuration:

\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
xleftmargin=3ex,
breaklines=true,
breakatwhitespace=false,
escapechar=`
}

the code is in the following place:

\begin{figure}[tb]
\HRule
\begin{lstlisting}
   MY LONG CODE
\end{lstlisting}
\HRule
\caption{some code.\label{fig:code}}
\end{figure}

Unfortunately the figure with code is not split between two pages,but shows only the part that fits single page.What may cause the problem and what is its solution?

  • 1
    figure is a box so prevents any page breaks. – David Carlisle Jan 24 '17 at 20:46
2

A floating environment cannot have a pagebreak! Use instead

\begin{lstlisting}[caption=some code.,label=fig:code]
   MY LONG CODE
\end{lstlisting}

If you want the caption below the code then use also captionpos=b.

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.