[Tex/LaTex] How to force \lstinline to add a line break

line-breakinglistings

I have an inline piece of code in my main LaTeX document that I have included using the \lstinline command:

\lstinline{template<class UIntType, UIntType a, UIntType c, UIntType m> class linear_congruential_engine;} 

The resulting output is shown below, which is really not ideal:

enter image description here

What I would like to do is to achieve something a bit more aesthetically appealing, where a newline is introduced before the second class keyword and the next line is indented 3 characters.

Here is a MWE:

\documentclass{article}
\usepackage{listings}

\begin{document}
\lstset{language=C++,
        basicstyle=\small\ttfamily,
        emptylines=1,
        breaklines=true}
\lstset{numbers=left,tabsize=2}
\setcounter{secnumdepth}{1}
\lstMakeShortInline[language=C++,basicstyle=\ttfamily]`

\section{Linear Congruential Generators}
text text text text:
% I want to add a newline after the second class keyword and indent with 3 spaces so that "class linear_congruental_engine" appears indented on the next line
\noindent\lstinline{template<class UIntType, UIntType a, UIntType c, UIntType m> class linear_congruential_engine} 
text text text
\end{document}

Here is a related question: Allowing line break at C++ operators ('::', '->', …) in \lstinline

Best Answer

I would suggest inserting an appropriate line-break inbetween two manually-separated \lstinline statements. That is,

...
\noindent\lstinline{template<class UIntType, UIntType a, UIntType c, UIntType m>} \par
\lstinline{class linear_congruential_engine}
...

You may want to add some spaces at the start of the second \lstinline, if needed.

Related Question