I have a List of Listings that looks like this:
The first listing, which is correct, uses lstlisting. 3.1
is the correct chapter.
The second listing uses minted. Somehow it shows 1
as chapter, which should actually be 3.2
.
This is my command for the List of Listings:
\renewcommand{\lstlistlistingname}{List of Listings}
\addcontentsline{toc}{chapter}{\listoflistingscaption}%
\listof{listing}{\listoflistingscaption}%
This is the first code:
\begin{lstlisting}[language=xml, frame=single, caption={"Segment of the XML input file"}, label={lst:xmlfile}]
some code
\end{lstlisting}
This is the second:
\begin{listing}[H]
\begin{minted}{c++}
some code
\end{minted}
\caption{"Conversion functions for DirID and ID"}
\label{lst:conversion}
\end{listing}
What do I need to change here so that it shows up correctly with the right chapter number?
Best Answer
The first thing you need is
\usepackage[chapter]{minted}
. This setsminted
to use<chapter>.<listing>
style numbering in the list of listings.At this point, listings from the two packages will have the same format in the list of listings, but each will be using its own number scheme. They need to share a common counter to fix this. A simple solution is to modify the
listing
environment fromminted
so that it actually uses thelstlisting
counter. This relies on theetoolbox
package, which is automatically loaded by recent versions ofminted
. The code can be inserted in the preamble afterminted
is loaded.