I use \lstinline{foo} from the listings package to set pieces of code in regular text. To get automatic line-breaks I use the following options:


Sometime code fragments have to go into rather narrow table cells and the automatic line breaks just don't look very nice.

Is there any way to tell \lstinline (and lstlisting) where to insert line-breaks without actually putting them into the LaTeX source literally? If I do hard code them this will influence line numbers (in lstlistings) and also the line continuation symbol and indentation will be missing.


2 Answers 2


You can certainly escape into LaTeX and force a break manually, for example

 breaklines        = true,
 breakatwhitespace = true,
 breakindent       = 2ex,
 escapechar        = *,
 numbers           = left

Some text
Some more text Some more text Some more text Some more text
Some more text Some more text *\break* Some more text Some more text
Final text


Whether this is what is required I'm not 100% sure: telling listings where to break without adding anything to the source seems extremely difficult to imagine.


If you only need this once and don't want to declare it with \lstset you can set breaklines to true directly in lstinline.

\lstinline[breaklines=true]|[this is a very long command]|
  • The OP already has breaklines in their code. The question is more about how to influence this automatic line-breaking.
    – Troy
    Commented Mar 8, 2018 at 23:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .