[Tex/LaTex] set the font family for lstlisting

fontsformattinglistings

I have the following set up for my listings :

\lstset{basicstyle=\footnotesize,breaklines=true}
\lstset{framextopmargin=50pt,frame=bottomline}

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

Best Answer

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

\documentclass[12pt]{article}
\usepackage{listings}
\usepackage{lipsum}
\usepackage{courier}

\lstset{basicstyle=\footnotesize\ttfamily,breaklines=true}
\lstset{framextopmargin=50pt,frame=bottomline}

\begin{document}
\begin{lstlisting}
   a b c
\end{lstlisting}
\lipsum[1]
\end{document}

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.

Related Question