5

I typeset my listings using listings with a proportional font. This looks good for the lstlisting environment. However, when I use \lstinline|code|, the spacing reverts to variable-width. I would like to use the setting columns=fixed with lstinline. If I \lstset it globally, it is ignored for \lstinline. Is there a way to set \lstinline to use columns=fixed without having to add it to every \lstinline in my source code?

Here is a minimal example:

\documentclass{article}

\usepackage{listings}
\lstset{columns=fixed}

\begin{document}
The code \lstinline|A.someMethodName()| is typeset differently from
\lstinline[columns=fixed]|A.someOtherMethodName()|.
\end{document}

2 Answers2

7

You can use the \lstMakeShortInline command to pass the columns=fixed option:

\documentclass{article}

\usepackage{listings}
\lstset{columns=fixed}
\lstMakeShortInline[columns=fixed]|

\begin{document}
The code \lstinline|A.someMethodName()| is typeset differently from
\lstinline[columns=fixed]|A.someOtherMethodName()|. Using \verb+\lstMakeShortInline[columns=fixed]|+ you get the expected result:
|A.someMethodName()|

\end{document}
Gonzalo Medina
  • 505,128
1

I had exactly the same problem and by reading through the documentation, I tried setting the keepspaces=true option in \lstset{...} and it seems to have the desired effect! Spaces are no longer eaten up ;-)

Alex
  • 11
  • 2
    It makes no difference with the code in the question. Could you please elaborate your answer? – Stefan Kottwitz Nov 08 '11 at 22:31
  • +1 I tried both and prefer this solution. For me, columns=fixed adds to much space between characters, which is ok for code blocks but looks weird for inline code. keepspaces=true does exactly what promised: it keeps spaces from disappearing without changing anything else. I used it as option to lstMakeShortInline though, not for lstset. – Cephalopod Aug 13 '13 at 13:56