Tell me more ×
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 am working on a thesis and putting together a "pretty" listing. I'm looking at setting up a small font style for a code view. What I have here is:

\usepackage{listings}
\lstset{language=C,
numberstyle=\footnotesize,
basicstyle=\footnotesize,
numbers=left,
stepnumber=1,
frame=shadowbox,
breaklines=true}
%\usepackage[subsection]{placeins}
\usepackage{float}

But this comes out in a typical kerned font, vs. I am looking for smaller monospace, say, 10 points or so.

share|improve this question
1  
Welcome to TeX.sx! Usually you should add a full minimal working example (MWE) that illustrates your problem. Then we can see what packages you are using etc. Here the \lstset seems to be enough, however. – Martin Scharrer Oct 29 '11 at 6:56
@MartinScharrer: Thanks! I will remember. – Paul Nathan Oct 29 '11 at 17:11

2 Answers

up vote 14 down vote accepted
basicstyle=\footnotesize\ttfamily,

or with package microtype

\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\newcommand\Small{\fontsize{9}{9.2}\selectfont}
\newcommand*\LSTfont{\Small\ttfamily\SetTracking{encoding=*}{-60}\lsstyle}
...
\begin{lstlisting}[basicstyle=\LSTfont,...]
...

Which gives a better result.

share|improve this answer

You are missing a \ttfamily in the basicstyle. If this doesn't give you the size you want try \scriptsize or even \tiny instead of \footnotesize. You don't need to add the same size for the numberstyle again because basicstyle is used for everything by default.

\documentclass{article}
\usepackage{listings}
\lstset{language=C,
numberstyle=\footnotesize,
basicstyle=\ttfamily\footnotesize,
numbers=left,
stepnumber=1,
frame=shadowbox,
breaklines=true}

\begin{document}
Normal text

\begin{lstlisting}
    int a, b, c;
    b = 2;
    c = b++;
    a = b + c;
\end{lstlisting}

Normal text
\end{document}
share|improve this answer
scriptsize worked for me, because it's between tiny and footnote size. it was the best trade off. – OneWorld Oct 8 '12 at 8:27

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.