# Listings code snippet has white horizontal lines across it

I'm using the listings package to typeset my code examples. I've set the background color to slightly off white color and I'm noticing strange white horizontal lines across the snippet. They seem to go right between every line.

Not sure if I should include my listings settings?

-
Including your settings is a great idea, it'd be even better if you included a minimal working example (MWE) that illustrates your problem and that narrows down your code to only that which is necessary to recreate your problem. –  doncherry May 15 '11 at 20:56
@doncherry: I was thinking about adding it when I wrote the question but then I kinda forgot... (was tired, last 2 weeks until hand-in) –  benregn May 16 '11 at 8:35

The background color and the frame are drawn for every line separately. listings assumes a certain line height and such graphic errors appear if the real height is larger than that. From your image I would guess you are using a larger font for the line numbers than for the normal text. You should set numberstyle to the same or smaller size than the normal text.

In my test I get the same white lines if the numberstyle is larger than the basicstyle (left) but not if it is smaller (right) or the same size.

\documentclass{article}

\usepackage{listings}
\usepackage{xcolor}

\begin{document}

\begin{minipage}{.2\textwidth}
\begin{lstlisting}[basicstyle=\scriptsize,numberstyle=\large,backgroundcolor=\color{black!20},numbers=left,frame=lrtb]
some code
more code
more code
more code
more code
more code
more code
more code
more code
\end{lstlisting}
\end{minipage}\hspace{2cm}%
\begin{minipage}{.2\textwidth}
\begin{lstlisting}[basicstyle=\scriptsize,numberstyle=\tiny,backgroundcolor=\color{black!20},numbers=left,frame=lrtb]
some code
more code
more code
more code
more code
more code
more code
more code
more code
\end{lstlisting}
\end{minipage}

\end{document}

-
One might also say numberstyle=\mymacro after having defined \newcommand{\mymacro}[1]{\smash{#1}}, because numberstyle=<x> executes \def\lst@numberstyle{<x>} and this command is called as \lst@numberstyle{\thelstnumber}. Additional formatting may be included in \mymacro (the name of this macro can be different, of course), for example for changing color. –  egreg May 15 '11 at 22:00
Thanks for clearing that up. I don't remember seeing anything about this in listings documentation... –  benregn May 16 '11 at 8:53
I have this issue without using line numbers. The white lines are very fine and their visibility depends on the zoom level in the PDF reader. –  h0b0 Jan 23 '12 at 11:24
@h0b0: That seems to be a PDF reader issue. Getting such artifacts depending on the zoom level is a well known issue with them. You could place the listing into a {adjustbox}{bgcolor=<your color>} environment (adjustbox package) instead, so that the background is drawn as one block. –  Martin Scharrer Jan 23 '12 at 11:42
@71GA: Okular and Evince might use the same internal PDF library or simply use the same or similar enough zooming algorithm. You can adjust the style to make the numbers more visible, but it will always be viewer dependent, IMHO. –  Martin Scharrer Mar 12 '12 at 21:54