1

I am currently writing a paper that has lots of code snippets in it, which I would like to treat as figures.

Because the examples can be very long it would be convenient to allow page breaks inside of the code.

Is there any way to achieve this?

\documentclass[12pt]{article} 

\usepackage{listings}
\usepackage{float}

\begin{figure}[ht]
\begin{lstlisting}[language=java]
...Here will be a very long code snippet...
\end{lstlisting}
\caption{Test}
\label{fig:test}
\end{figure}
2
  • You cannot, flots are by definition single page. Btw di you know that lstlisting has a build in caption feature?
    – daleif
    Apr 28 '21 at 7:38
  • @daleif No I did not know that. Thank you a lot!
    – Manox
    Apr 28 '21 at 7:41
1

Float are by definition single page only. If you just want to label/caption your source sniplets, listings has build in features for that. See the listings manual

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.