使用多列显示更宽的标题

使用多列显示更宽的标题

我正在使用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}

在此处输入图片描述

相关内容