Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
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. –  Peteris Krumins Apr 30 '11 at 11:24
3  
@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 Answer 1

up vote 14 down vote accepted

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.

share|improve this answer
3  
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

 
discard

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.