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?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityjust add to the \lstset{...}
-section
lineskip={-1.5pt}
and: voilá!
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}
\usepackage{setspace}
in the preamble and insert TeX code directly in the beginning\singlespacing
and in the end\onehalfspacing
of your listings.