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.

  • 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

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.

  • 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.


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.