I'm using the \captionof
command from the caption
package to add captions to listings produced with \inputminted
. E.g.
\documentclass{report}
\usepackage{caption}
\usepackage{minted}
\begin{document}
\chapter{The first chapter}
\captionof{listing}{some code}
\begin{minted}{C}
#define X 1
\end{minted}
\chapter{The second chapter}
\captionof{listing}{some more code}
\begin{minted}{C}
#define Y 2
\end{minted}
\end{document}
This seems to be the only way to add captions to listings produced by minted that still allows listings to span multiple pages. What annoys me greatly is that I am not able to figure out how to number the resulting listings hierarchically. They show up as Listing 1
and Listing 2
but I'd rather have them numbered Listing 1.1
, Listing 2.1
and so forth according to the chapter they are in (akin to numbering of floats). How can I achieve this?