3

Is there an option to break line in an lstlisting's caption? For example:

\begin{lstlisting}[frame=single, caption=uppertext\\lowertext)]

I've tried with \\ and some other solutions, but any of them works.

2

You can set the caption using a tabular. However, also set the optional caption (for the \lstlistoflistings) without the line-breaking tabular:

enter image description here

\documentclass{article}

\usepackage{listings}

\begin{document}

\lstlistoflistings

\begin{lstlisting}[
    frame = single, 
    caption = {[upper/lower text]%
               \begin{tabular}[t]{@{}l@{}}
                 upper text \\
                 lower text \\[.5\normalbaselineskip]
               \end{tabular}}
              ]
Hello world
\end{lstlisting}

\end{document}

Due to the frame, some vertical adjustment is needed (in the form of \\[.5\normalbaselineskip]).

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.