使用 multicol 列出更寬的標題

使用 multicol 列出更寬的標題

我正在使用multicollistings包。我希望將標題分佈在多列清單的整個清單中。

這是我正在嘗試的 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環境(而非密鑰multicols);標題是使用包\captionof中的caption可選參數進行排版的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}

在此輸入影像描述

相關內容