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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use the listings package. If a line break inside a multi-word \lstinline{} occurs, I get a nasty spaces at the beginning of the new line:

page left                  page right
    |                          |   
    |normal text normal text IF|
    | FORALL normal text       | 

IF FORALL is inside a \lstinline{}.

How to avoid the space before FORALL?


EDIT: I don't mind to elaborate. I am typing a document that includes some inline code snippets. I use \lstinline{} to typeset them (since I also use lstlisting in my document).

The illustration above depicts the result from latex code:

normal text normal text \lstinline{IF FORALL} normal text

Now if IF FORALL does fit into a single line, I get

    |normal text normal text IF FORALL normal|
    |text                                    | 

on my page, which is fine. The | mark the start of the page margin.

If IF FORALL is broken down into multiple lines, I get the result shown above. I would much rather like to have:

    |normal text normal text IF|
    |FORALL normal text        | 

Hope that this makes it more clear. Thanks.

share|improve this question
Start by posting a minimal example of what you are doing. – Joseph Wright Sep 30 '10 at 20:32
Let me know if this makes it more clear – Frank Seifert Oct 5 '10 at 12:41
This is a lot better. – Caramdir Oct 5 '10 at 14:27
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – Jubobs Feb 27 '14 at 11:33

The space is the one between the IF and the FORALL. I don't know if it is possible to eat it somehow, but you can at least move a bit back:

normal text normal text \lstinline{IF FORALL} normal text

Addition: I just realized, that the space disappears too if you use \lstset{breaklines,breakatwhitespace}

Addition 2: An obvious solution which avoids all this hassle with the white space is to use two \lstinline commands: \lstinline{IF} \lstinline{FORALL}.

share|improve this answer
@Ulrike: Your first solution doesn't work: -1ex isn't quite correct, but that's not the main problem. If you increase the text width to 4.3cm, then "IF " fits on the first line, and the second line starts with "FORALL", moved to the left by -1ex. That's definitely not desired. Your second solutions seems to work perfectly, at least with a recent TeX installation! So could you please replace your first solution with the second one? – Hendrik Vogt Oct 22 '10 at 14:13
Well no: the second doesn't work perfectly either, as then (with textwidth=4.3cm) the first line is a bit to short (the space behind the IF is there). The perfect solution is postbreak=\kern-1ex when the break is before the space and prebreak=\kern-1ex if the break is after the space. – Ulrike Fischer Oct 22 '10 at 15:18
Oh my, you're right, the breakatwhitespace option doesn't solve the problem either. To me this seems like a bug in the package. Anyway, this breakatwhitespace isn't well documented. Still your \kern-1ex isn't perfect, but it's not clear how to make it better: It seems that the width of the white space varies depending on the letters around it. So at the moment, your "Addition 2" seems like the best solution. – Hendrik Vogt Oct 22 '10 at 17:26

This doesn't answer your question per se, but what I do is either rewrite the text so that the listing fits on a single line, or if that is not possible for whatever reason, then make it a nonfloating listing. This takes a little extra space, but I think it is more readable than having it break.

share|improve this answer
up vote 0 down vote accepted

This is apparently not implemented at this time.

share|improve this answer

Your Answer


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.