![为什么使用 ACM 样式制作的程序列表会产生非常窄的标题?](https://linux22.com/image/334502/%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BD%BF%E7%94%A8%20ACM%20%E6%A0%B7%E5%BC%8F%E5%88%B6%E4%BD%9C%E7%9A%84%E7%A8%8B%E5%BA%8F%E5%88%97%E8%A1%A8%E4%BC%9A%E4%BA%A7%E7%94%9F%E9%9D%9E%E5%B8%B8%E7%AA%84%E7%9A%84%E6%A0%87%E9%A2%98%EF%BC%9F.png)
答案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}