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}

5
  • 1
    Make a complete example. That makes it much easier to test the issue. Feb 6, 2020 at 14:24
  • Done. I have included a complete example. Thanks Feb 6, 2020 at 14:37
  • Also related: tex.stackexchange.com/questions/238840/…
    – Marijn
    Feb 6, 2020 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 6, 2020 at 14:50
  • This one answers tex.stackexchange.com/questions/238840/…. Yet the solution bellow is better because it does not require auxiliary packages Feb 6, 2020 at 17:11

1 Answer 1

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}
2
  • Following your suggestion the second listing appears with 2.2. It should be 2.1 Feb 6, 2020 at 14:53
  • @FernandoMiguelCarvalho thanks, I edited the answer. Feb 6, 2020 at 14:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.