8

Why does \lstinline not break lines correctly like with \begin{lstlisting}? The text goes over the documentborder with \lstinline.

Thank you!

\documentclass{scrreprt}

\usepackage{listings}

\lstset
{
    breaklines=true,
    breakatwhitespace=true,
    frame=lines,
    basicstyle=\ttfamily,
}

\begin{document}

    \begin{lstlisting}            
someverylongcode, whichneedssomelinebreak hereandthere, becauseotherwiseitwouldgooverthedocumentborder
    \end{lstlisting}

\lstinline[language=C]!someverylongcode, whichneedssomelinebreak hereandthere, becauseotherwiseitwouldgooverthedocumentborder!

\end{document}
1
  • 2
    \lstinline is \lstinline, not lstonmorethanoneline, i.e. it's not meant for multiline - display
    – user31729
    Dec 3, 2015 at 15:43

1 Answer 1

5

\lstinline can do linebreaks, but it doesn't stretch the spaces and so it only works in a \raggedright or \sloppy context:

\documentclass{scrreprt}

\usepackage{listings}

\lstset
{
    breaklines=true,
}

\begin{document}

\lstinline[language=C]!someverylongcode, whichneedssomelinebreak hereandthere, becauseotherwiseitwouldgooverthedocumentborder!

\raggedright
\lstinline[language=C]!someverylongcode, whichneedssomelinebreak hereandthere, becauseotherwiseitwouldgooverthedocumentborder!

\end{document}

enter image description here

1
  • 3
    Thank you that works! How can I undo \raggedright after \lstinline? But I think I will try to avoid long code inline or use normal lstlistings instead. Dec 4, 2015 at 8:35

You must log in to answer this question.

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