2

When I want to put a simple caption to my listing, tex puts the number of the subheading to the listing and not the actual listing number.

\begin{lstlisting}[language=Python, caption=Listing 1: caption, captionpos=b]
 some code 
\end{lstlisting}

As you see here, it also adds the chapter number instead of only listing 1.

1
  • 2
    Welcome to TeX.SE. Please reveal which document class you employ. – Mico May 2 at 12:20
4

listings offers the numberbychapter option which is initially set to true. Using \lstset{numberbychapter=false} you can make sure, listings are numbered continuously throughout the document without the chapter number prefix:

\documentclass{report}
\usepackage{listings}
\lstset{numberbychapter=false}
\begin{document}
\chapter{chapter}

\begin{lstlisting}[language=Python, caption=caption, captionpos=b]
 some code 
\end{lstlisting}
\end{document}

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.