Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linenumbering with listings package in latex

Tags:

latex

listings

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} 
like image 313
ted Avatar asked Feb 01 '10 16:02

ted


People also ask

How do I show line numbers in LATEX?

To turn line numbers on, type :set nu and press Return. Line numbers appear in the left margin. Note that these numbers do not appear when you print out the file.

What is listings LATEX?

The listings package is a source code printer for LATEX. You can typeset stand alone files as well as listings with an environment similar to verbatim as well as you can print code snippets using a command similar to \verb.

How do I show line numbers in TeXworks?

At the top of the TeXworks window, select Edit, then Preferences. Select the "Editor" tab and check the "Line numbers" box. Click OK.

How do I reference a line in LATEX?

sty allows to refer to a line number with \ref{<label>} . The label is set by \linelabel{<label>} , anywhere in a paragraph that gets line numbers.


1 Answers

You can get the desired numbering like this:

\lstset{   numbers=left,   stepnumber=5,       firstnumber=1,   numberfirstline=true } 
like image 91
Fabian Steeg Avatar answered Sep 23 '22 09:09

Fabian Steeg