I want to use the caption package to insert a horizontal bar above the caption/title of a lstlisting environment (+ some other stylings which are not relevant here). The minimal example below shows a (slightly simplified) call to \DeclareCaptionFormat that achieves that.

However, as one can see in the second lstlisting environment below, the rule above the caption (and the caption itself) extend to the full page width when called inside an itemize environment. I would have expected the rule above the caption to look like the two frame lines above and below the listing. What am I doing wrong?


\captionsetup{format = lstlisting}

\lstset{title=Title, frame=lines}

line 1
line 2
\item Listing:
line 1
line 2

enter image description here

  • My first guess would be that itemize sees listing as some sort of sublist and indents it accordingly. I tried putting the listing in enumerate and description and the same thing happened. – Plergux Nov 3 '20 at 8:48

Your Answer

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

Browse other questions tagged or ask your own question.