0

All my listings labels appear with prefix 1. in all sections, such as the following example, where the second listing of my paper in section 2 appears with the prefix 1. rather than 2.

I have already realized that \maketitle is the root of this behavior. If I remove \maketitle the labels appear correctly with 1 and 2, rather than 1.1 and 1.2.

How can we keep consistent numbering with the following llncs template:

\documentclass[runningheads]{llncs}

\usepackage{listings}

\begin{document}

\title{PetClinic Sample}

\maketitle

\section{Intro}
\label{sec:alternatives}

We will use the PetClinic Spring~\ref{lst:input}

\begin{lstlisting}[language={HTML}, caption={Button}, label={lst:button} ]    
<button></button>
\end{lstlisting}

\section{Idioms}

\begin{lstlisting}[language={HTML},caption={Input},label={lst:input}]    
<input>
\end{lstlisting}


\end{document}

  • 1
    Make a complete example. That makes it much easier to test the issue. – Ulrike Fischer Feb 06 '20 at 14:24
  • Done. I have included a complete example. Thanks – Fernando Miguel Carvalho Feb 06 '20 at 14:37
  • Also related: https://tex.stackexchange.com/questions/238840/how-to-number-listings-by-section-number – Marijn Feb 06 '20 at 14:49
  • 1
    From the proposed duplicates: \usepackage{chngcntr}\begin{document}\counterwithout{lstlisting}{section} will number listings continuously and not per section. However, Springer may not like it if you do that, so if you are planning to submit this somewhere then it may be changed back upon publication. – Marijn Feb 06 '20 at 14:50
  • This one answers https://tex.stackexchange.com/questions/238840/how-to-number-listings-by-section-number. Yet the solution bellow is better because it does not require auxiliary packages – Fernando Miguel Carvalho Feb 06 '20 at 17:11

1 Answers1

1

As your class sets up a chapter counter listings uses it. You can switch to section like this:

\documentclass[runningheads]{llncs}

\usepackage{listings}
\AtBeginDocument{\counterwithin{lstlisting}{section}%
             \renewcommand\thelstlisting{\thesection.\arabic{lstlisting}}}

\begin{document}

\title{PetClinic Sample}

\maketitle

\section{Intro}
\label{sec:alternatives}

We will use the PetClinic Spring~\ref{lst:input}

\begin{lstlisting}[language={HTML}, caption={Button}, label={lst:button} ]
<button></button>
\end{lstlisting}

\section{Idioms}

\begin{lstlisting}[language={HTML},caption={Input},label={lst:input}]
<input>
\end{lstlisting}


\end{document}
Ulrike Fischer
  • 327,261