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?
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?
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.
Modify your basicstyle to include the font family:
\lstset{basicstyle=\ttfamily\footnotesize,breaklines=true}
\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
Nov 18 '23 at 13:19
\ttfamily(from Computer Modern)? – Werner Nov 04 '11 at 20:44basicstyle=\ttfamilyprints the listing content using\ttfamily- a monospaced font. – Werner Nov 04 '11 at 20:52\ttfamilyis a Computer Modern font which looks very similar to Adobe's Courier. Adding\usepackage{courier}overrides the\ttfamilyoutput to now represent Courier. If the similarities are negligible to you, just use\ttfamily. It's that simple. – Werner Nov 04 '11 at 20:58\texttt{...}or{\ttfamily ...}which produces the same result. – Werner Nov 04 '11 at 21:20