So I have looked at the following:

Suppress line numbering for specific lines in listings package

And the solution works great for the nth line of code. What if I want to suppress the very first line of code? Can not make it suppress the very first line...

1 Answer 1


Basis Ideas

The idea here is very simple. Simply define two styles, one with no line number, another with line numbers. Then input the first line of listing with the first style, input the rest with the second style.

The first attempt produced a small hitch where the physical second line was being numbered 1. A patch from https://tex.stackexchange.com/a/27240/14103, helped here.

The Code

Simply copy the required portions to your file preamble. To input your code files use, \getfilewithnofirslinenumber{filename}.




% Your input files
\begin{filecontents*}{\jobname code1.xml}

\begin{filecontents*}{\jobname code2.xml}
  <XML Version 1.0>

% Define numbering and nonumbering styles

% For file input

% This part has been taken from
% https://tex.stackexchange.com/a/27240/14103. Delete/comment out the
% following if you want your physical second line to be numbered 1.
\patchcmd{\lst@GLI@}% <command>
  {\def\lst@firstline{#1\relax}}% <search>
  {\def\lst@firstline{#1\relax}\def\lst@firstnumber{#1\relax}}% <replace>
  {\typeout{listings firstnumber=firstline}}% <success>
  {\typeout{listings firstnumber not set}}% <failure>


The first line numbers in codes are not shown.

First file.

\getfilewithnofirslinenumber{\jobname code1.xml}



Second file with only one line.

\getfilewithnofirslinenumber{\jobname code2.xml}


The Output

enter image description here


Definitely you will want to set the code language, your own styles for code font, number appearance etc.

Should you want your physical second line to be numbered 1, delete/comment out the portion:


You must log in to answer this question.

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