6

When using the \lstinline macro from listings, like

\lstinline|subl| 

some extra whitespace is added to the intended text. It is especially painful at the end of the line: it behaves as if it were a new paragraph, and adds some unwanted indentation. How can I get rid off this? See the example below: the comma immediately following \lstinline goes to the beginning of the next line.

enter image description here

\documentclass{book}
\usepackage{listings}
\lstset{breaklines,postbreak=\kern-1ex}
\textwidth=4cm
\parindent=0cm
\begin{document}
normal text normal text \lstinline{reg1}, \lstinline{reg2}, normal text
\end{document}
jub0bs
  • 58,916
katang
  • 1,429
  • Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – jub0bs Jan 18 '15 at 18:12
  • Will these \lstinlines always fit on one line or can the be expected to linebreak in the middle of the \lstinline? If one line, then \mbox{\lstinline{reg1},} would work. – Steven B. Segletes Jan 19 '15 at 13:00
  • Check out http://tex.stackexchange.com/a/200494/21891 – jub0bs Jan 19 '15 at 16:01
  • @Steven B. Segletes The extra whitespace remains, so this solution only prevents line break, but not continuous writing. – katang Jan 19 '15 at 20:13
  • I understand from you reply that you need the ability to perform line breaks within the \lstinline. – Steven B. Segletes Jan 19 '15 at 20:14
  • @Steven B. Segletes No, I simply want a smooth continuation, i.e. no space before the next comma, especially not to transfer the comma to the beginning of the next line; and especially not to put the extra white space to the beginning of the next line, within a paragraph. – katang Jan 20 '15 at 13:42
  • 1
    @Steven B. Segletes I simply want to write a continuous text, like "instructions like \lstinline|add|, \lstinline|sub| and \lstinline|mul|" and the unwanted space in \lstinline makes the output ugly, either by separating the inline text and the comma following it, or even starting an unwanted indentation in the next , starting with space and comma at the beginning. – katang Jan 24 '15 at 18:21
  • If your \lstinline argument always consists of a single word (without spaces), then the \mbox{\lstinline{reg1},} approach I mentioned above should work fine. The issue is if you have a multi-word argument that you desire to break across lines, that is a more difficult problem. – Steven B. Segletes Jan 24 '15 at 18:40
  • 1
    What is the purpose of the breaklines,postbreak=\kern-1ex options here when you say you don't need to break inline listings across lines? Removing those options fixes the issue – siracusa Oct 18 '18 at 21:45

0 Answers0