I'm using the listings package to include some source code excerpts in my document. It offers the
float
option to create a float with the code inside.Now, I need two snippets to be closely together because they demonstrate a code transformation. Normally I would use a
subfigure
but this will put the listings in the "List of Figures", not the "List of Listings". Can I change this somehow or is there some other way to combine two listing in a float?MWE:
Code: Select all
\documentclass{article}
\usepackage{listings}
\lstset{
frame=single,
captionpos=b,
frameround=tttt
}
\usepackage{caption,subcaption}
\pagestyle{empty}
\begin{document}
\listoffigures
\lstlistoflistings
\clearpage
\begin{figure}
\begin{subfigure}{\linewidth}
\centering
\begin{lstlisting}
Listing 1
\end{lstlisting}
\caption{Listing 1}
\end{subfigure}
\vspace{2em}
\begin{subfigure}{\linewidth}
\centering
\begin{lstlisting}
Listing 2
\end{lstlisting}
\caption{Listing 2}
\end{subfigure}
\caption{Two listings}
\end{figure}
\begin{lstlisting}[float, caption={Listing 3}]
Listing 3
\end{lstlisting}
\end{document}