linenumbering with listings package in latex

ted picture ted · Feb 1, 2010 · Viewed 34k times · Source

I am trying to insert a code snippet with the listingspackage, and want the lines numbered. However I would like only every 5th line and the first to be numbered (numbers beeing(1,5,10,15,...)) according to the manual:

stepnumber=5

should do the trick, however using my minimal example (see bottom), I get the line numbers 1,6,11,16,...

May be I misinterpreted he manual 8did that once before), however I am clueless.

If a real latex guru is around, there would be something I would like even more, having every linenumber printed however every fifth in bold/ a different style numbers than beeing: 1 2 3 4 5 6 7 8 9 10 11 ... however since this is not in the doku I am sure it requires some deeper latex/listings knowledge.

P.S.: There is one more oddity, eventhough I put "numberfirstline=false" I get the line number 1 ( I get that linenumber as well without setting numberfirstline, which should default to false), it is jsu in there to point out that something is wrong.

I am using miktex for compilation, if that helps.

Thanks in advance.

\documentclass{scrreprt}        %[twoside,headings=openright]
%Sourcecode formatting
\usepackage{listings}

\lstset{
         numbers=left,               % Ort der Zeilennummern
         stepnumber=5,               % Abstand zwischen den Zeilennummern       
         numberfirstline=false
 }

\begin{document}
\lstinputlisting{sourcecode/AES/lookupSoftcoded.S} %codefile with 15 lines or so...
\end{document}

Answer

Fabian Steeg picture Fabian Steeg · Feb 1, 2010

You can get the desired numbering like this:

\lstset{
  numbers=left,
  stepnumber=5,    
  firstnumber=1,
  numberfirstline=true
}