答案1
该类acmsmall
只知道figure
,table
因此它假设,如果浮点数不是figure
,那么它就是table
。
\@makecaption
您可以反转选择标题格式样式的逻辑,因此它仅适用于表格的“短”文本宽度。
\documentclass {acmsmall} % Aptara syntax
\usepackage{listings}
\usepackage{etoolbox}
\makeatletter
\def\TabName{table}
\patchcmd{\@makecaption}
{\ifx\FigName}
{\unless\ifx\TabName}
{}{}
\makeatother
\begin{document}
\begin{lstlisting}[caption={Just to demonstrate an extra narrow listing caption},float]
# some line
\end{lstlisting}
\begin{lstlisting}[
caption={
Just to demonstrate an extra narrow listing caption
Just to demonstrate an extra narrow listing caption
Just to demonstrate an extra narrow listing caption
Just to demonstrate an extra narrow listing caption}]
# some line
\end{lstlisting}
\begin{figure}
\caption{some long caption to see what happens}
\end{figure}
\end{document}