3

I want to prepare a manuscipt for an ACM journal. The program listing appears with extra narrow caption, see at bottom. It is hard to believe, I found incompatility with package 'listings', in an ACM style file. But, the MWE works fine with styles book, memoir, etc. Any better idea?

\documentclass {acmsmall} % Aptara syntax
\usepackage{listings}

\begin{document}

\lstinputlisting[caption ={Just to demonstrate an extra narrow listing caption}]{sample.asm}

\end{document}

The extra narrow listing

1 Answer 1

1

The acmsmall class only knows figure and table so it assumes that, if a float is not figure, it is table.

You can reverse the logic whereby the \@makecaption selects the caption formatting styles, so it only applies “short” text width for tables.

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

enter image description here

4
  • The solution is perfect, until 'float' option is used in \lstlisting. :(
    – katang
    May 22, 2016 at 19:21
  • @katang I changed the patch; now all floats are treated like figure except table. In the example, one of the lstlisting is declared as a float in order to show the patch works.
    – egreg
    May 22, 2016 at 19:31
  • Thank you, although I do not understand, why it is necessary to make exception with tables.
    – katang
    May 23, 2016 at 14:06
  • @katang The class wants to typeset table caption with the same width as the table
    – egreg
    May 23, 2016 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .