1

If I create a code include as follows:

\lstinputlisting[linerange=39-46, firstnumber=39]{./Matlab/script.m}

And set the stepnumber to 5 in the lstset:

\lstset{...,stepnumber = 5, ...}

Line 40, 45 and 39 are numbered but I only want to number line 1, 5, 10 etc. So in this example 39 should not be displayed. Firstnumber=auto starts not at the true line number.

1

1 Answer 1

2

The following works like requested:

\documentclass{article}% at line 39
\usepackage{listings}
\begin{document}

\lstset{stepnumber=5}
\lstinputlisting[
  language={[LaTeX]TeX},
  linerange=39-46,
  firstnumber=39,
  numbers=left,
]{test.tex}

\end{document}

Result

Only lines numbers 40 and 45 are shown.

Or if the numbering should start at 1 (firstnumber=1) and the first line should also be numbered (numberfirstline):

\documentclass{article}% at line 39
\usepackage{listings}
\begin{document}

\lstset{stepnumber=5,numberfirstline}
\lstinputlisting[
  language={[LaTeX]TeX},
  linerange=39-46,
  firstnumber=1,
  numbers=left,
]{test.tex}

\end{document}

Result

Version of package listings is 2007/02/22 v1.4.

1
  • Thanks for your contribution, it turned out that in my preamble I declared: numberfirstline = true in the lstset option. This should be set to false for this specific list inclusion. However, it is mandatory to force displaying a 1 for the first line number as it is not modulo 5. Apr 26, 2013 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .