2

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.
3
  • you'd probably be more likely to get an answer if you did provide an example and say what error you got, many of us will not have used the class but it's usually possible to debug an example, if provided. Commented Apr 17, 2017 at 21:24
  • @DavidCarlisle: The thing is, I've already tried a dozen different combinations of things which haven't worked out, but I didn't do it systematically so I can't recount any of it. But - you know what? Challenge accepted. I'll make this more concrete (within a day or two).
    – einpoklum
    Commented Apr 17, 2017 at 21:37
  • @DavidCarlisle: Working on it right now. First thing I found - my captioning was being thwarted because I had defined a command named \tblname. Big mistake... onwards.
    – einpoklum
    Commented Apr 18, 2017 at 20:01

3 Answers 3

5

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{[email protected]}
\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

5
  • 1
    (1) About autoref vs \cref - I used \autoref since acmart already uses hyperref; with that in mind, do you still believe \cref should be preferred? (2) Are you suggesting that subcaption should be preferred over subfig always, or just for acmart documents? (3) Your images look like everything is typeset in heavier weight somehow, plus I edited a bit, so perhaps this should be regenerated.
    – einpoklum
    Commented Apr 18, 2017 at 21:54
  • @einpoklum In general, subcaption is to be preferred over subfig. I see no “heavier” typesetting. Your first edit removed some comments from the code; the second one adds text that I find useless.
    – egreg
    Commented Apr 18, 2017 at 22:10
  • @egreg Shouldn't the example in the first section reference third-subfig and fourth-subfig? Commented Nov 27, 2017 at 16:19
  • @MichaelMior Possibly so, I believe I used some random references.
    – egreg
    Commented Nov 27, 2017 at 16:32
  • @egreg It seems like you were intending to refer to specific subfigures and you mistakenly picked the wrong ones. Not worth redoing the images for though I suppose :) Commented Nov 27, 2017 at 17:26
2

Section 2.12 of the user guide recommends subcaption package "for complex figures with several subplots or subfigures that require separate subcaptioning."

2
  • You're right. But I wasn't using subcaption before. Do you think there's a good reason to use that over subfig? (see my answer below)
    – einpoklum
    Commented Apr 18, 2017 at 21:40
  • @einpoklum For instance, subcaption is compatible with hyperref, whereas subfig isn't completely so.
    – egreg
    Commented Apr 18, 2017 at 21:49
1

Ok, the following works. Feedback in comments is appreciated regarding the choice of packages or anything else.

\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{float}
\usepackage{subfig}

\begin{document}

\title{Tables, figures and subfigures \\ with the new ACM 2017 article template}

\author{Nobody in particular}
\affiliation{ \institution{University of Life} }
\email{[email protected]}

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

Le'ts add a figure with two subfigures; the subfigures will be added using 
\verb|\subfloat[caption goes here]|, so they should also be captioned. 
That will be \autoref{first-figure-with-subfigures}.

\begin{figure}[htpb]
  \centering
  \subfloat[Some subfigure]{
    \graphicsplaceholder{4cm}{1cm}
    \label{first-subfig}
  }
  \subfloat[Another subfigure]{
    \graphicsplaceholder{4cm}{1cm}
    \label{second-subfig}
  }
  \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
\autoref{a-two-column-figure}.

\begin{figure*}[htpb]
  \centering
  \subfloat[Yet another caption]{
    \graphicsplaceholder{8cm}{1cm}
    \label{third-subfig}
  }
  \subfloat[This is getting old]{
    \graphicsplaceholder{8cm}{1cm}
    \label{fourth-subfig}
  }
  \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 \autoref{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}

And when I compile this with TeXLive 2015.20160320-1 (the distribution-provided version on Linux Mint 18.1), I get two pages:

Page 1 of 2 of the output Page 2 of 2 of the output

Notes:

  • The reason I don't use subcaption is that, well, this is close to what I was using with older ACM classes, and I've opted for minimum changes to get things working (but feel free to criticize).
  • I don't know why I get the block starting with "ACM Reference Format". Do they do that on purpose? It's really hard on the eyes and annoying.
  • I'm not sure how to balance the columns now (but this example is not about column balancing).
  • There's no page numbering - probably since these things go inside proceedings PDF's which have their running numbers over many articles.
  • I'm not quite sure why the figure* environment clears the page. Shouldn't the text just fill up the two columns before it, with the figure coming afterwards? Hmm.
3
  • subfigure has been obsolete for at least 15 years.
    – egreg
    Commented Apr 18, 2017 at 21:23
  • @egreg: Hmm. I remembered some packages are obsolete, but I somehow manage to get them confused. Fixed.
    – einpoklum
    Commented Apr 18, 2017 at 21:38
  • have you figured out how to place figure* on the same page where it was declared? In your example, it is a bit difficult, since it is the first page. But I'm trying to have a wide figure on top of second page (written in text that belongs to 2nd page), but it keeps getting placed on 3rd one, despite htbp modifier Commented Mar 28, 2018 at 21:55

You must log in to answer this question.

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