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 using Beamer and lstlisting to put some code in a presentation.

The character spacing feels a bit too wide to my eye. Is it possible to reduce it? I've tried searching on this SE but can't seem to see anything obvious.

EDIT:

This seems trivial but:

\begin{frame}[fragile]
\frametitle{A frame}
\begin{lstlisting}
the letters are too far apart
\end{lstlisting}
\end{frame}
share|improve this question
    
Welcome to TeX.SX! Could you please add an example of what you mean? –  egreg Sep 10 '12 at 14:48
    
Done, unless you want the complete file, \usepackage and all? –  Joe Sep 10 '12 at 14:57
    
Try \begin{lstlisting}[columns=fullflexible] and tell whether it's better. –  egreg Sep 10 '12 at 15:02
    
@Joe: better would be a complete example, because you can use some options loading package listings which could be important ... –  Kurt Sep 10 '12 at 15:04
    
Thanks @egreg that is exactly what I wanted. Give it as an answer and I'll tick it. –  Joe Sep 10 '12 at 15:10
add comment

1 Answer

up vote 5 down vote accepted

The default setting of listings is to place each character in a box in order to ensure vertical alignment emulating terminal output.

However, this may not be nice when the default font is proportionally spaced. There are two solutions (actually one):

\lstset{columns=fullflexible}

in the document preamble will typeset in normal character boxes. However, usually listings are typeset with a monospaced font, so

\lstset{columns=fullflexible,basicfamily=\ttfamily}

will do both settings.

The key-value pair can also be specified on a local basis:

\begin{lstlisting}[columns=fullflexible,basicfamily=\ttfamily]

will apply the settings only to that lstlisting environment.

The key keepspaces will also avoid merging two spaces into one.

share|improve this answer
    
Brilliant thanks. –  Joe Sep 10 '12 at 15:18
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.