# How to skip first line lstlistings

I need help for lstlistings. I have a code that start with:

INPUT: c, m
rest of code...


I want that the first line doesn't view the number line. This is my lstset:

\lstset{language=Java,
numberstyle=\scriptsize,
numbers=left,
numbersep=5pt,
numberblanklines=false,
captionpos=b,
basicstyle=\small\sffamily,
columns=fullflexible,
xleftmargin=16pt,
frame=leftline,
breaklines=true,
tabsize=2,
prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
escapeinside={$}{$}
}


• – Werner
Sep 25, 2014 at 23:16
• Welcome to TeX.SE. It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. Also, I'd recommend you include the input and the desired output (it is not clear from your description). Sep 25, 2014 at 23:58

While listings provides the key-value numberfirstline (set to false by default), it doesn't seem to deliver on the promise of not numbering the first line. As such, the following is work-around: Start "numbering" from 0 and check when printing the number whether it should be printed or not using a conditional.

\documentclass{article}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
numberstyle=\small\ttfamily,
%numberfirstline=false,
firstnumber=0,
numbers=left
}
\makeatletter
\def\lst@PlaceNumber{\ifnum\value{lstnumber}=0\else
\llap{\normalfont\lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\fi}
\makeatother
\begin{document}
\begin{lstlisting}
INPUT: c, m
rest of code...
\end{lstlisting}
\end{document}


If placement of the number is to the right (using numbers=right), then the following redefinition of \lst@PlaceNumber is required:

\makeatletter
\def\lst@PlaceNumber{\ifnum\value{lstnumber}=0\else
\rlap{\normalfont\kern\linewidth \kern\lst@numbersep\lst@numberstyle{\thelstnumber}}\fi}
\makeatother


Note that these redefinitions of \lst@PlaceNumber should occur after setting the numbers option.

• Can you hide line numbers from the first three line, for instance? Is there any way to generalize your solution?
– Ido
Sep 30, 2020 at 8:48
• @Ido: Try with \ifnum\value{lstnumber}<2\else ... \fi.
– Werner
Oct 3, 2020 at 4:43

Add firstline=2 in the \lstset.

\lstset{language=Java,
firstline=2,
numberstyle=\scriptsize,
numbers=left,
numbersep=5pt,
numberblanklines=false,
captionpos=b,
basicstyle=\small\sffamily,
columns=fullflexible,
xleftmargin=16pt,
frame=leftline,
breaklines=true,
tabsize=2,
prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
escapeinside={$}{$}
}

• This will ignore the first line entirely, while the OP seems to be interested in just having it not numbered.
– Werner
Sep 26, 2014 at 5:45