0

I have a question analogous to this one, but for listings instead of figures.

In my TeX file, I have multiple listings defined as follows:

\begin{lstlisting}[caption={A really, really, really, really, really long caption}]
<code>
\end{lstlisting}

Now, my List of Listings uses the entire caption, which looks slightly silly. Is there a way to define a short caption for the LoL just like the \caption[short caption]{long caption} command for the LoF?

1 Answer 1

2

From the manual page 34:

caption={[⟨short⟩]⟨caption text⟩}

The caption is made of \lstlistingname followed by a running number, a seperator, and ⟨caption text⟩. Either the caption text or, if present, ⟨short⟩ will be used for the list of listings.

So in your case:

\begin{lstlisting}[caption={[short caption]{long caption}}]
<code>
\end{lstlisting}

Should do.

Note the {} wrapping the caption argument to avoid the closing ] to be interpreted as "end of optional argument for lstlisting.

2
  • Thank you! Small correction: Your closing brackets are slightly off. It needs to be [caption={[short caption]{long caption}}].
    – jpfender
    Commented May 17, 2016 at 10:28
  • yes, corrected =)
    – Bordaigorl
    Commented May 17, 2016 at 13:50

You must log in to answer this question.

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