Legenda mais ampla para listagem usando multicol

Legenda mais ampla para listagem usando multicol

Estou usando os pacotes multicole listings. Gostaria que a legenda fosse espalhada por toda a listagem para listagens com várias colunas.

Aqui está um MWE do que estou tentando, porém a saída é indesejável porque a legenda é colocada apenas na primeira coluna.

\documentclass{article}
\usepackage{listings}
\usepackage{multicol}

\begin{document}

\begin{lstlisting}[caption={A longer caption that ideally spans all the columns in the listing, otherwise it just does not look right if you get what I mean}, multicols=3]

text not important
text not important
text not important
text not important
text not important
text not important

text not important
text not important
text not important
text not important
text not important
text not important

\end{lstlisting}

\end{document}

Responder1

Aqui está uma possibilidade, usando explicitamente o multicolsambiente (em vez da multicolschave); a legenda é composta usando \captionofo captionpacote, usando o argumento opcional de multicols:

\documentclass{article}
\usepackage{caption}
\usepackage{listings}
\usepackage{multicol}

\begin{document}

\begin{multicols}{3}[\captionof{lstlisting}{A longer caption that ideally spans all the columns in the listing, otherwise it just does not look right if you get what I mean}]
\begin{lstlisting}

text not important
text not important
text not important
text not important
text not important
text not important

text not important
text not important
text not important
text not important
text not important
text not important

\end{lstlisting}
\end{multicols}

\end{document}

insira a descrição da imagem aqui

informação relacionada