14

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.

lockstep
  • 250,273
  • 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
  • 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

1 Answers1

15

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

basicstyle=\ttfamily

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

Spike
  • 6,729
  • 4
    I find basicstyle=\footnotesize\ttfamily even better for the default LaTeX layout. – Andrey Vihrov Apr 30 '11 at 11:14
  • http://tex.stackexchange.com/questions/33685/set-the-font-family-for-lstlisting – Say OL Aug 26 '13 at 10:22
  • 3
    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