段組みを使用したリストのキャプションの幅を広くする

段組みを使用したリストのキャプションの幅を広くする

multicol私はおよびパッケージを使用していますlistings。複数列のリストにキャプションをリスト全体に表示したいと思います。

これは私が試みていることの MWE ですが、キャプションが最初の列にのみ配置されるため、出力は望ましくありません。

\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}

答え1

ここに、明示的にmulticols環境を使用する 1 つの可能性を示します (キーの代わりにmulticols)。キャプションは、のオプション引数を使用して、パッケージ\captionofからタイプセットされます。captionmulticols

\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}

ここに画像の説明を入力してください

関連情報