i'd like to use the name=something,firstlinenumber=auto
function for continuous line numbering throughout a couple of subsequent listings in my document. I'd also like to have each of the listings have its own separate entry in the List of Listings. The listings
package seems to not like that, though: If I use the same name=something
for multiple listings, only the first one gets an entry in the List of Listings, every other one does not. If I do not use name=something
, each listing gets it's own entry in the List of Listings, but the continuous line numbering no longer works. Minimal example:
\documentclass{article}
\usepackage{listings}
\lstset{numbers=left,firstnumber=auto}
\begin{document}
\lstlistoflistings
\section{Contents}
\begin{lstlisting}[name=test,label=first,caption=First Listing]
this should start at line number 1
and should be the first entry in the List of Listings
\end{lstlisting}
Listing~\ref{first} shows up correctly in the List of Listings.
\begin{lstlisting}[name=test,label=second,caption=Second Listing]
this continues line numbers from the previous listing
but does not get an entry in the List of Listings
\end{lstlisting}
Listing~\ref{second} continues the line numbering, and has its own listing number
that can be referenced, but does not receive an entry in the list of Listings.
% parameter "name=test" is removed here..
\begin{lstlisting}[label=third,caption=Third Listing]
this restarts the line numbers from line 1
but does get a second entry in the List of Listings
\end{lstlisting}
Listing~\ref{third} also has its own listing number that can be referenced, and
does get an entry in the List of Listings, but does not continue line numbers.
\end{document}
Obviously I could manually count each listings' lines and then manually set the starting line number for each subsequent listing, but I'd prefer a more robust automatic solution. Does anyone know a way to get both behaviors, continuous line numbers AND separate List of Listings entries?
Thanks in advance!