I have the following set up for my listings :


I would like to change the font family to Courier. How can I enable this?

  • Why not just use a monospaced font like \ttfamily (from Computer Modern)?
    – Werner
    Commented Nov 4, 2011 at 20:44
  • @Werner I am sorry but I am not following you here. You might have got that I am newbie :s
    – tugberk
    Commented Nov 4, 2011 at 20:45
  • 1
    It is recommendable to take a look at Section 4.6 of the listings manual. Commented Nov 4, 2011 at 20:51
  • 7
    @tugberk: See @Peter's answer. basicstyle=\ttfamily prints the listing content using \ttfamily - a monospaced font.
    – Werner
    Commented Nov 4, 2011 at 20:52
  • @Werner what does ttfamily actually do here? To me, just a miracle happen there. I didn't say the you can use the courier. I just put the ttfamily there.
    – tugberk
    Commented Nov 4, 2011 at 20:55

3 Answers 3


With \usepackage{courier} in your preamble you can use the courier font in the listings as follows:



   a b c

The \usepackage{courier} in the preamble causes \ttfamily to produce output in the courier font. Without including this package, you can still use \ttfamily to get a mono spaced font by including that as part of the basicstyle=... setting.

  • 11
    Wouldn't this solution affect the fonts of the entire document? Or am I missing something? Commented Sep 5, 2019 at 15:27
  • @AdrianKeister: Did you try running the MWE? Commented Sep 5, 2019 at 16:11
  • @AdrianKeister this is not the case.
    – Genfood
    Commented Jan 7 at 17:53

Modify your basicstyle to include the font family:

  • This proved to be a far better answer as it does not impact the whole document.
    – Andry
    Commented Sep 26, 2019 at 15:46

If you use \lstset{basicstyle=\fontfamily{pcr}\footnotesize} it will set only the font used in listings to Courier. Original response where this snippet was found is here. A list containing some of the supported fonts can be found here.

  • Warning: \fontfamily should be followed by \selectfont, in this case it just happen to work because it's followed by \footnotesize -- in particular if you swap the 2 commands it will not work anymore.
    – user202729
    Commented Nov 18, 2023 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .