# Allow page breaks inside figures

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}

• You cannot, flots are by definition single page. Btw di you know that lstlisting has a build in caption feature? Apr 28 '21 at 7:38
• @daleif No I did not know that. Thank you a lot! Apr 28 '21 at 7:41