7

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?

1
  • 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, 2013 at 9:46

2 Answers 2

8

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

lineskip={-1.5pt}

and: voilá!

3
  • 1
    Welcome to TeX.SX! This is rather a comment than an answer
    – user31729
    Mar 19, 2015 at 15:09
  • 2
    @SoundsOfSilence IMO this is an answer, why do you say otherwise? (It perhaps a somewhat hackish solution, but there are plenty of those around.) Mar 19, 2015 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, 2015 at 17:06
4

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.