# Renumber listing

I am using listings to add some codes, as shown in the image

For this I use the following:

\lstset{language= python, breaklines=true,basicstyle=\footnotesize}

\lstset{numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt}


And

\begin{lstlisting}[frame=single]
sage: s0.series(z,6)
1 + 1*z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + Order(z^6)
\end{lstlisting}

\begin{lstlisting}[frame=single]
sage: s1.series(z,6)
1*z^(-1) + (-1) + (-1)*z + (-2)*z^2 + (-5)*z^3 + (-14)*z^4 + (-42)*z^5 + Order(z^6)
\end{lstlisting}


what I am looking for is that the number on the left in the second box starts the count from 3 (because it is the third line), and as you can see it starts from 1, as in the first box. Anyone knows how to solve this?

Use either an explicit value for the firstnumber argument, or select last if you want the numbering to continue.

\documentclass{article}

\usepackage{listings}
\usepackage{xfp,refcount}

\lstset{
language=python,
breaklines=true,
basicstyle=\footnotesize,
numbers=left,
numberstyle=\tiny,
stepnumber=1,
numbersep=5pt
}

\begin{document}

\begin{lstlisting}[frame=single]
sage: s0.series(z,6)
1 + 1*z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + Order(z^6)
\end{lstlisting}

% firstnumber set to an explicit fixed value
\begin{lstlisting}[frame=single,firstnumber=3]
sage: s1.series(z,6)
1*z^(-1) + (-1) + (-1)*z + (-2)*z^2 + (-5)*z^3 + (-14)*z^4 + (-42)*z^5 + Order(z^6)
\end{lstlisting}

% firstnumber set to continue from the last value
\begin{lstlisting}[frame=single,firstnumber=last]
sage: s3.series(z,6)
1 + 1*z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + Order(z^6)
\end{lstlisting}

\end{document}

• firstnumber worked perfect, thanks Oct 1, 2022 at 17:28