[Tex/LaTex] Idiomatic approach to captioned subfigures and tables with the 2017 acmart class

acmacmartcaptionsfloatssubfloats

In late 2016, the ACM published its 2017 ACM Master Article Template. This document class breaks a lot of LaTeX code one might have written using earlier ACM document classes, specifically the sig-alternate class.

Specifically, I've been having trouble captioning tables, and using subfigures (captioned or otherwise), with the new class. The user's guide says nothing about this, specifically not in Section 2.5, dealing with figures and tables.

Instead of asking about something specific which did not work for me, what I'd like to know is the common, idiomatic if you will, approach to this issue:

  • Which combination(s) of packages to use with the class (subfigure, subcaption, subfig, floatrow etc.)?
  • Is there some special initialization, \patchcmding or other voodoo incantation I should include in my preamble?
  • Are there specific figure/subfigure layouts I should avoid, or be careful about? Ditto w.r.t. captioning.

Best Answer

Just to expand Boris’ answer, here's how you can (and should) do with subcaption. Instead of \autoref I believe it's better to use \cref from \cleveref.

\documentclass[sigconf]{acmart}

%---------------------------------------------------------------
% You don't need this block of lines in your article - I do
% need, them since I use placeholders instead of actual graphics
\usepackage{tcolorbox} % for graphics placeholders
\newcommand{\graphicsplaceholder}[2]{%
  \begin{tcolorbox}[valign=center,width=#1,height=#2,arc=0.5mm,auto outer arc]%
    \centering \sf missing graphic%
  \end{tcolorbox}%
}
%---------------------------------------------------------------

\usepackage{subcaption}
\usepackage{cleveref}

\crefname{figure}{Figure}{Figures}

\begin{document}

\title{Tables, figures and subfigures \texorpdfstring{\\}{}
   with the new ACM 2017 article template}
\author{Nobody in particular}
\affiliation{\institution{University of Life}}
\email{no.body@life.edu}
\maketitle

\begin{abstract}
The quick brown fox jumps over the lazy dog.
\end{abstract}

\section{Figures}

Let's start with a simple figure, single-column, no subfigures --- using a
\texttt{figure} environment. That will be \cref{figure-with-no-subfigs}.

\begin{figure}[htpb]
  \centering
  % What you would typically have here is something like:
  % \includegraphics[width=\columnwidth]{some-file.pdf}
  % but for this example, let's go with a placeholder instead:
  \graphicsplaceholder{8cm}{1cm}
  \caption{This is a figure with no subfigures}
  \label{figure-with-no-subfigs}
\end{figure}

\subsection{Figures with subfigures}

Let's add a figure with two subfigures; the subfigures will be added with
\verb|\subcaptionbox{caption goes here}|, so they should also be captioned. 
That will be \cref{first-figure-with-subfigures}.

\begin{figure}[htpb]
  \centering
  \subcaptionbox{Some subfigure\label{first-subfig}}{%
    % What you would typically have here is something like:
    % \includegraphics[width=0.2\textwidth]{some-file.pdf}
    % but for this example, let's go with a placeholder instead:
    \graphicsplaceholder{4cm}{1cm}%
  }
  \subcaptionbox{Another subfigure\label{second-subfig}}{%
    \graphicsplaceholder{4cm}{1cm}%
  }
  \caption{A caption for the single-column figure with two subfigures}
  \label{first-figure-with-subfigures}
\end{figure}

Let's conclude this section by repeating the same figure, but now as a 
two-column figure, i.e. using the \verb|{figure*}| environment. That will 
be \cref{a-two-column-figure}, with \cref{first-subfig} and \cref{second-subfig}.

\begin{figure*}[htpb]
  \centering
  \subcaptionbox{Yet another caption\label{third-subfig}}{%
    \graphicsplaceholder{8cm}{1cm}%
  }
  \subcaptionbox{This is getting old\label{fourth-subfig}}{%
    \graphicsplaceholder{8cm}{1cm}%
  }
  \caption{A caption for the two-column figure (also with two subfigures)}
  \label{a-two-column-figure}
\end{figure*}

\section{Tables}

Let's add a \texttt{table} environment, with a caption near the end of it
(after the \texttt{tabular} environment). That will be \cref{first-table}.

\begin{table}[thpb]
\begin{tabular}{ c c c }
  1 & 2 & 3 \\
  4 & 5 & 6 \\
  7 & 8 & 9 \\
\end{tabular}
\caption{This is a caption for a \texttt{table} float, with a 
  \texttt{tabular} environment inside it}
\label{first-table}
\end{table}

And we're all done, except for one last thing...:

\paragraph{Warning} Don't ever define a \verb|\tblname| command. This was 
possible with older ACM document class (e.g. \texttt{sig-alternate} v2.8), 
but now it will trigger errors when you try to caption your floats.

\end{document}

enter image description here

Related Question