Does anyone know how to change the font for code snippets in the listings package? I'd like to have a constant width font, rather the fancy variable-width looking font that it has by default.

  • 3
    Please read the manual first. It took me less than ten seconds to find the answer via google. – Thorsten Apr 30 '11 at 11:17
  • 7
    @Thorsten, It was not obvious that basicstyle changed the font. I did read the manual but I searched for font and didn't find the answer. – Peter Krumins Apr 30 '11 at 11:24
  • 4
    @PeterisKrumins Thank for asking the question here. I too was looking for this information, and searched for font as you did. I have the listings package PDF, I did a 15-minute search of the 58-page document, and the answer was not obvious to me. I needed the answer faster than having to read 58 pages first (just to change a font). Google led me to StackExchange and this page and the answer right away. Thank you for saving me time. – gknauth Apr 17 '13 at 21:11

As shown at page 28 of the manual, adding the option


to the \lstset{} command would make what you ask.
Keep in mind to always read the packages documentation on your machine before posting.

  • 3
    I find basicstyle=\footnotesize\ttfamily even better for the default LaTeX layout. – Andrey Vihrov Apr 30 '11 at 11:14
  • 2
    Keep an open mind: Peteris Krumins maybe tried to read the documentation and found it incomprehensible. Actually, that's why I'm here. +1 for your answer. – User 17670 Oct 28 '13 at 17:41

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.