TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Lyx's Insert|Program Listing to insert a code listing into my document. Unfortunately, Lyx seems to ignore the Typewriter font selection I made in DocumentOptions under Fonts ⇒ Typewriter. Interestingly enough, typewriter font does come out correctly elsewhere, but not in program linstings.

Can someone help me figure out why? I'm using Lyx 2.0.2 and am using XeTeX for output.

share|improve this question
Have you changed the listing to actually use typewriter fonts? By default, they are not used. – Torbjørn T. Apr 25 '12 at 11:42
No, I haven't. I assumed they'd be used automatically. If that's not the case, how do I make this setting document-wide? Also, I think the letter spacing in program listings is wrong (wider than normal), is there any way to get it to 'default' levels? – Dmitri Nesteruk Apr 25 '12 at 11:48
I added a suggestion about the spacing issue to my answer. – Torbjørn T. Apr 25 '12 at 11:57
up vote 8 down vote accepted

Program listings does not actually use the typewriter font family by default, so you have to change this in the settings. To change it for a single listing, right click it, choose Settings and select Typewriter as Font family.

enter image description here

To make it a global change, go to Document --> Settings --> Listings, and type in the following option:


For the spacing, try adding


to the options list for listings. I'm not entirely sure about this, though the different choices for columns is described in the listings manual (listings is the package used for these program listings), section 2.10 Fixed and flexible columns.

share|improve this answer
Thanks, I get it now. What about letter spacing - can that be fixed too? Or am I imagining things? – Dmitri Nesteruk Apr 25 '12 at 11:55
Actually, I've just tried \basicstyle{\ttfamily} and XeTeX gave me an Undefined control sequence. – Dmitri Nesteruk Apr 25 '12 at 13:32
@DmitriNesteruk There is no backslash before basicstyle and an = after. – Torbjørn T. Apr 25 '12 at 13:39
Whoops, my bad. – Dmitri Nesteruk Apr 25 '12 at 13:43

I still use LyX 1.6, the more recent version available for Windows 2000 (which I have in a couple of PCs). In LyX 1.6.10 you don't find the "Listings" module in the "Document->Settings" menu. So you solve this issue by adding


to the "Latex Preamble" box in the "Document->Settings" menu.

share|improve this answer
Welcome to TeX.SX. – Claudio Fiandrino Apr 25 '13 at 16:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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