4

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}
  • 2
    \lstinline is \lstinline, not lstonmorethanoneline, i.e. it's not meant for multiline - display – user31729 Dec 3 '15 at 15:43
3

\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

  • 2
    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. – honiahaka10 Dec 4 '15 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.