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?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityWith \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}
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.
\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.
Nov 18 at 13:19
\ttfamily
(from Computer Modern)?basicstyle=\ttfamily
prints the listing content using\ttfamily
- a monospaced font.