# How to reduce Program-Listing line spacing in LyX

Using LyX 2.06.

I have a standard document with 1.5 line spacing, but I want my program listings to use 1.0 line spacing. Is there a simple way to do this?

• You'll probably need to load some package like `\usepackage{setspace}` in the preamble and insert TeX code directly in the beginning `\singlespacing` and in the end `\onehalfspacing` of your listings. – juliohm Nov 7 '13 at 9:46

just add to the `\lstset{...}`-section

``````lineskip={-1.5pt}
``````

and: voilá!

• Welcome to TeX.SX! This is rather a comment than an answer – user31729 Mar 19 '15 at 15:09
• @SoundsOfSilence IMO this is an answer, why do you say otherwise? (It perhaps a somewhat hackish solution, but there are plenty of those around.) – Torbjørn T. Mar 19 '15 at 17:04
• @TorbjørnT. IMO it's a short comment rather, but I did not flag it, to keep it alive ;-) – user31729 Mar 19 '15 at 17:06

You can add the `\singlespacing` command from `setspace` (which LyX uses when you set the linespacing to OneHalf or Double) to the `\basicstyle` of the listings. This will basically add `\singlespacing` (and any other commands added there) at the start of every code listing. A side effect of this seems to be that some additional whitespace is added before every listing, this can be fixed by setting `aboveskip`, which is another parameter for Listings, to a negative length.

Hence, go to Document --> Settings --> Listings, and add

``````basicstyle={\singlespacing},aboveskip={-4ex}
``````

You may want to change the length `4ex`. If you have changed the `\basicstyle` already, just add `\singlespacing` at the end, e.g.

``````basicstyle={\ttfamily\singlespacing},aboveskip={-4ex}
``````