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've just noticed that the spacing between letters is different in verbatim vs. lstlisting environments: example of the difference in letter spacing

Given that I add the option columns=flexible to the lstlisting environment, the spacing in this environment looks similar to the one in the verbatim environment. Is it possible to do the reverse, i.e. to make the text in the verbatim environment look like the text in the lstlisting environment (possibly using the fancyvrb package)?

Below is the sample code I used:

\documentclass{article}
\usepackage{verbatim}
\usepackage{listings}

\begin{document}

\begin{lstlisting}[basicstyle=\ttfamily]
  Dummy code
\end{lstlisting}

\begin{verbatim}
  Dummy code
\end{verbatim}

\end{document}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

That's one of the features of listings I like the less: letterspacing lowercase text is a capital sin. However, here's how you can do it (don't tell Frederic Goudy, please).

\documentclass{article}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{microtype}
\makeatletter
\g@addto@macro\verbatim@font{\lsstyle}
\makeatother

\begin{document}

\begin{lstlisting}[basicstyle=\ttfamily]
  Dummy code
\end{lstlisting}

\begin{verbatim}
  Dummy code
\end{verbatim}

\end{document}

enter image description here

The small difference is due to the fact that letterspacing is applied only between letters. You may have also to increase the interword spacing.

share|improve this answer

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.