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 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}
share|improve this question

2 Answers 2

up vote 6 down vote accepted

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}
share|improve this answer

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 ;-)

share|improve this answer
2  
It makes no difference with the code in the question. Could you please elaborate your answer? –  Stefan Kottwitz Nov 8 '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

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.