5

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

5
  • Can you add a compilable MWE to your question?
    – astronat
    Commented Apr 4, 2016 at 18:36
  • Sorry for the novice question...what's a MWE? Commented Apr 4, 2016 at 18:44
  • Minimal Working Example, i.e. a compilable piece of code that contains the problem you're working on, so that others can try it and work out how to fix it. Essentially it's the bare bones of your .tex file. More info here: meta.tex.stackexchange.com/questions/228/…
    – astronat
    Commented Apr 4, 2016 at 20:24
  • It seems sufficient to use \lstinline{... m>} \par \lstinline{class ...} (and you could add spaces before the second class inside \lstinline, if needed).
    – Werner
    Commented Apr 4, 2016 at 20:59
  • @Werner. Yes that actually worked! I don't know why I was hell-bent on trying to put the entire expression in a single \lstinline. If you put this as an answer I will accept it :) Commented Apr 4, 2016 at 21:07

1 Answer 1

5

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.

You must log in to answer this question.

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