I am trying to control the spacing between the line numbers and my code with the listings package. Below follows the code I am using:

\begin{figure*} [!ht]
    INPORT::[name] => [rec.comp.] @ [rec. port]
    OUTPORT::[name] <= [orig.comp.] @ [out port]
    [PRIMITIVE]::[name]<=[rec.port2]<-[orig.comp1.]@[out port1] [rec.port2]<-[orig.comp2.]@[out port2]...
    LUT[n] [logic_func]::[name]<=[rec.port2]<-[orig.comp1.]@[out port1] [rec.port2]<-[orig.comp2.]@[out port2]...
    \caption{single line component netlist of the tiny circuit example.}

The result I am getting is as follows:

enter image description here

I am not happy with the spacing between the code and numbers and I am trying to change it by changing the numbersep parameter, as it says in the package documentation, "is the distance between number and listing". Even when I use '0pt' I am not getting the code and the numbers close.

What am I missing here?

1 Answer 1


lstlisting is a verbatim type environment, and crucially spaces are preserved. Your code starts with four spaces, and you're seeing those four spaces.

If you set showspaces=true in your \lstset (you currently have it set to false) this becomes obvious.


To strip the spaces you can add


to the \lstset.

There is also a package called lstautogobble which provides an option called autogobble. With this option starting whitespace is automatically removed.

  • Thank you for your feedback. So as I could understand from your answer, in other to have numbers and code close I would have to use another package right? Any suggestion you could give me here or should I change the question or ask another question and leave this as is?
    – elrhod
    Commented Mar 28, 2020 at 22:23
  • @elrhod (I suppose I could have searched this a bit more before answering ...) You can tell listings to remove the first N characters of the line with the gobble option, so try \begin{lstlisting}[gobble=4], or add that option to the \lstset.There is also a package for automatic gobbling of whitespace: add \usepackage{lstautogobble} to the preamble, and autogobble to the \lstset. (From tex.stackexchange.com/questions/19953/…) Commented Mar 28, 2020 at 22:41
  • Adding the "gobble=4" to the \lstset worked perfectly! Thanks again.
    – elrhod
    Commented Mar 28, 2020 at 23:10

You must log in to answer this question.

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