# Setting up specific font for use in listings

I'm writing my dissertion using TeX. I would like to use a specific font in my lstlisting source code. How can I use a specific font like Monaco or Arial? I usually found solutions with basicstyle setted to \ttfamily but it's not what I want.

-
possible duplicate of Verbatim text can't be shown correctly in pdf –  Marco Daniel Nov 10 '11 at 15:20
Welcome to TeX.SE. Altough it may seem trivial it is always best to compose a MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill Nov 10 '11 at 15:23
@MarcoDaniel Why should this be a duplicate of that question? –  egreg Nov 10 '11 at 16:19
@egreg: I am showing how you can set the font with the package listings and fancyvrb. –  Marco Daniel Nov 10 '11 at 16:28
@egreg: I think the op is searching something like \lstset{basicstyle=\fontsize{10pt}{10}\usefont{OT1}{ptm}{m}{n}} –  Marco Daniel Nov 10 '11 at 16:42

Instead of \ttfamily you can use all the other commands which select a font. E.g.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\lstset{basicstyle=\fontfamily{pzc}\selectfont} %Zapf

\begin{document}
\begin{lstlisting}
abcde
\end{lstlisting}
\end{document}

-

You can't use a font in TeX unless it's known to the TeX system. For example Monaco isn't, unless you use XeLaTeX or LuaLaTeX on Mac OS X. A good typewriter font for pdflatex can be BeraMono:

\usepackage[scaled]{beramono}


and then \ttfamily will use this font. You can say also scaled=.85 or some other number, in order to accommodate the size to your main font.

There's a clone of Courier

\usepackage{tgcursor}


that sports a neat distinction between medium and bold weight (but might not agree with your main font).

However, you're not forced to use typewriter type for listings; if you say

\lstset{basicstyle=\sffamily}


you'll get whatever sans serif font is the default. You can change the default font by loading the suitable package; for example

\usepackage{tgheros}


will load a clone of Helvetica as the sans serif font and the above declaration will make this one the default. This package has a scale option similar to the scaled for beramono. Note that Arial is not considered to be a free font, so it's not in standard TeX distributions.

If you're using XeLaTeX or LuaLaTeX as typesetting engines, then you can use whatever OpenType or TrueType font you have on your system. For example, after having loaded fontspec you can define a suitable command

\usepackage{fontspec}
...
\newfontfamily{\lstsansserif}[Scale=.85]{Arial}


and then \lstset{basicstyle=\lstsansserif} would use Arial for listings.

-