So i've been using the listings package to include some C and MATLAB source code in my document. The code is fairly long, so i'd like to have line numbers along the left margin. I only need them every 5th line or so. Something like 5,10,15,20. Nice and even looking. The problem is, if i set stepnumber=5, it doesn't number them this way. It gives me 1,6,11,16,21, etc. I know it's a relatively minor issue, but i was wondering if anyone knows how to fix this. Also, for some reason setting numberfirstline=false does not seem to do anything. no matter what, it will put a number on line 1.
Any thoughts?
Text Formatting ⇒ 'listings' package line numbering problems
'listings' package line numbering problems
Hi,
yes, there seems to be some bug with the numberfirstline option. (I do not know if it is really a bug or if it was planned to work that way, and the documentation doesn't clarifies this). The following test code will produce (as you already experienced) a numbered first line:
However, adding something like firstnumber=1, the numberfirstline=false option works as expected:
yes, there seems to be some bug with the numberfirstline option. (I do not know if it is really a bug or if it was planned to work that way, and the documentation doesn't clarifies this). The following test code will produce (as you already experienced) a numbered first line:
Code: Select all
\documentclass{article}
\usepackage{listings}
\lstset{numbers=left, numberstyle=\tiny, stepnumber=5,%
numberfirstline=false, numbersep=5pt}
\begin{document}
The first line will be numbered:
\begin{lstlisting}[name=Test]
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\end{lstlisting}
\end{document}
Code: Select all
\documentclass{article}
\usepackage{listings}
\lstset{numbers=left, numberstyle=\tiny, stepnumber=5,%
numberfirstline=false, numbersep=5pt, firstnumber=1}
\begin{document}
The first line won't be numbered:
\begin{lstlisting}[name=Test]
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\end{lstlisting}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...