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

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.

share|improve this question
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
@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. – Peteris Krumins Apr 30 '11 at 11:24
@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
up vote 15 down vote accepted

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.

share|improve this answer
I find basicstyle=\footnotesize\ttfamily even better for the default LaTeX layout. – Andrey Vihrov Apr 30 '11 at 11:14
Awesome, thanks for help! – Peteris Krumins Apr 30 '11 at 11:23
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 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.