[Tex/LaTex] How to line-number 1,5,10,15,20,25… in Program Listing in Lyx

listingslyx

I basically want every 5th line numbered, but would like to keep to 5,10,15,20,… as that seems intuitive to readers. So that means 1,5,10,15,… The first gap is 4, all subsequent ones are 5. Is there a way to do this? Thanks!

Best Answer

This can be done with a combination of firstnumber and numberfirstline:

\documentclass{article}
\usepackage{listings}
\lstset{numbers=left,stepnumber=5,firstnumber=1,numberfirstline}
\begin{document}
\begin{lstlisting}
a
b
c
d
A
B
C
D
E
a
b
c
d
e
Q
\end{lstlisting}
\end{document}

yields:

listings

[I assume you are using the listings package.]

Related Question