Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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
3  
@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
show 4 more comments

2 Answers

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.

share|improve this answer
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.