Text Formatting ⇒ 'listings' package line numbering problems
'listings' package line numbering problems
Any thoughts?
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
'listings' package line numbering problems
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}