Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inconsistent letter spacing in listings package

108 views
Skip to first unread message

porst17

unread,
Oct 10, 2008, 5:53:32 AM10/10/08
to
Hi, I recently switched to the listings package for typesetting code
fragments. The package uses different letter spacings for inline code
(\lstinline) and code written inside the lstlisting environment. Here
is a minimal example:

\documentclass{scrartcl}

\usepackage{parskip}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}

\begin{document}
\lstinline!ab c de fg hijk lmno pqr st u vwyxz!\\
\lstinline!a bc de f g hi jk lmno pqr st u vwyxz!
\begin{lstlisting}
ab c de fg hijk lmno pqr st u vwyxz
a bc de f g hi jk lmno pqr st u vwyxz
\end{lstlisting}
\begin{verbatim}
ab c de fg hijk lmno pqr st u vwyxz
a bc de f g hi jk lmno pqr st u vwyxz
\end{verbatim}
\end{document}

The spacing with \lstinline matched the spacing with verbatim. but the
lstlisting environment uses larger spaces.

Is there any way to change this behavior?

Thanks for your help.

Martin Heller

unread,
Oct 10, 2008, 5:53:49 AM10/10/08
to
porst17 skrev:

> The spacing with \lstinline matched the spacing with verbatim. but the
> lstlisting environment uses larger spaces.
>
> Is there any way to change this behavior?

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

Ulrike Fischer

unread,
Oct 10, 2008, 5:56:32 AM10/10/08
to

\begin{lstlisting}[columns=flexible]

--
Ulrike Fischer

porst17

unread,
Oct 13, 2008, 5:15:23 AM10/13/08
to
Thank you very much. Now lstlisting works as expected for me.

Will Robertson

unread,
Oct 13, 2008, 10:54:56 PM10/13/08
to
On Oct 10, 7:56 pm, Ulrike Fischer <ne...@nililand.de> wrote:
>
> \begin{lstlisting}[columns=flexible]

While we're on the topic, is there any way to get multiple spaces to
line up correctly with this option? See below, where the ascii
indentation is completely broken:

\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily,columns=flexible}


\begin{document}
\lstinline!ab c de fg hijk lmno pqr st u vwyxz!\\
\lstinline!a bc de f g hi jk lmno pqr st u vwyxz!
\begin{lstlisting}

line up to here ->
spaces up to <- here
\end{lstlisting}
\end{document}

Cheers,
Will

Ulrike Fischer

unread,
Oct 14, 2008, 4:16:10 AM10/14/08
to
Am Mon, 13 Oct 2008 19:54:56 -0700 (PDT) schrieb Will Robertson:

>> \begin{lstlisting}[columns=flexible]
>
> While we're on the topic, is there any way to get multiple spaces to
> line up correctly with this option?

You could misuse the showspace option:

\listfiles
\documentclass{article}
\usepackage{listings}

\lstset{basicstyle=\ttfamily,columns=flexible,showspaces=true}


\begin{document}
\noindent


\lstinline!ab c de fg hijk lmno pqr st u vwyxz!\\
\lstinline!a bc de f g hi jk lmno pqr st u vwyxz!
\begin{lstlisting}
line up to here ->
spaces up to <- here
\end{lstlisting}

\makeatletter
\def\lst@visiblespace{\phantom{\lst@ttfamily{\char32}\textvisiblespace}}
\makeatother


\begin{lstlisting}
line up to here ->
spaces up to <- here
\end{lstlisting}

\end{document}


--
Ulrike Fischer

Will Robertson

unread,
Oct 14, 2008, 6:45:22 AM10/14/08
to
On 2008-10-14 18:46:10 +1030, Ulrike Fischer <ne...@nililand.de> said:

> You could misuse the showspace option:

Nice idea, thanks!
This is one of the reasons I've stuck to fancyvrb still (in many cases).

Cheers,
Will

0 new messages