12

I am looking for condensed mono spaced (typewriter) fonts to typeset program listings with pdflatex. The fonts should have the common shapes (up and italic or slanted) and series (normal and bold). Any suggestions?

2
  • By "typewriter" font, I assume you mean monospaced, right? Separately, will you be running pdflatex, xelatex, or lualatex?
    – Mico
    Commented Mar 10, 2012 at 3:50
  • @Mico Yes, I mean mono spaced fonts. I will be running pdflatex.
    – Romildo
    Commented Mar 10, 2012 at 8:38

4 Answers 4

15

Latin Modern ha a condensed version of the typewriter font:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}

\begin{document}
\ttfamily\lipsum[1]

\fontseries{lc}\selectfont
\lipsum[1]

\end{document}

enter image description here

If you need the text justified, you have to modify the \fontdimenX values

5

I do not know any free fonts satisfying your requirements. If you can consider non free fonts. I would recommend The Sans Mono Condensed Font designed by Lucas de Groot specifically for typesetting program code: http://www.lucasfonts.com/fonts/thesansmono/thesansmono-condensed/. Years ago I wrote LaTeX support package for it: http://www.ctan.org/pkg/thsmc. Of course XeTeX can use this font directly.

1
  • The Sans Mono Condensed is the same font used by O'Reilly programming books for code listings. Beautiful font.
    – rpattabi
    Commented Aug 25, 2014 at 4:59
4

Instead of looking for condensed fonts, you can also just change the size of the default font. I find that Latin Modern in \footnotesize looks quite good in listings:

\documentclass{article}

\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{listings}

\lstset{%
  basicstyle=\footnotesize\ttfamily,%
  numbers=left,%
  numberstyle=\footnotesize,%
  tabsize=2%
}

\begin{document}

\lipsum[1]

\begin{lstlisting}[language=C]
#include <stdio.h>

int main(void)
{
    printf("Hello World!\n");
}
\end{lstlisting}

\end{document}

Latin Modern typewriter font has normal and bold series, but the difference is subtle. You can try passing the lighttt option to the lmodern package for more distinction.

You can also browse The LaTeX Font Catalogue.

4

There is beramono:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[scaled=.83]{beramono}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\ttfamily\lipsum[1]

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .