# Empty caption of subfigure in memoir slightly misaligned

Consider the following minimal example meant to illustrate a single figure with a subfigure using the memoir documentclass:

\documentclass{memoir}
\newsubfloat{figure}% Allow for subfloats (subfigures) within figure environment
\begin{document}
\begin{figure}
\centering
\caption{This is a caption}
\end{figure}
\end{document}


The caption of the subfigure is empty so that it only displays the subfigure counter - '(a)' in this case:

However, the subfigure label is not perfectly centered the way I had hoped with an empty caption. Changing the subfigure definition (using some negative spacing via $\!\!$) to

\documentclass{memoir}
\newsubfloat{figure}% Allow for subfloats (subfigures) within figure environment
\begin{document}
\begin{figure}
\centering
\subbottom[$\!\!$]{\rule{2pt}{3em}\quad\rule{2pt}{3em}\quad\rule{2pt}{3em}}%
\caption{This is a caption}
\end{figure}
\end{document}


instead produces a more acceptable empty subfigure caption, however minuscule the difference:

Is this a known bug, or at least fixable?

-
that is the space between (a) and the caption. Seems like a bug because memoir already tests if the contents of [] is empty. –  Herbert Jul 14 '11 at 7:51
@Herbert Actually it doesn't test for emptyness, but it tests whether the contents is \@empty, which happens if there is no optional argument. –  egreg Jul 14 '11 at 18:06

The label leaves a space before the subcaption; it's necessary to kill it if there's no subcaption.

\makeatletter
\def\@memsubfig[#1]{%
\@ifnextchar [%
{\@memsubfloat{sub\@captype}[#1]}%
{\@memsubfloat{sub\@captype}[\@empty #1][#1\unskip]}}
\makeatother


## Some explanations

The complete syntax of \subbottom is

\subbottom[A][B]{<figure code>}


where A is the entry for the list of figures (tables) and B is the subcaption (they may be different just like captions for figures and tables). When B is not expressed, it's assumed to be the same as A. If also A is missing, no subcaption is set, not even the letter.

The control is actually passed to some other macros and eventually \@memsubfig is called when A is present (it will be substituted for #1 in the code). This macro checks if there is another optional argument. If there is, then

\@memsubfloat{subfigure}[A][B]


will be evaluated, otherwise LaTeX will be confronted with

\@memsubfloat{subfigure}[\@empty A][A]


(Note: we assume to be dealing with a figure; for a table, \@captype would be table.) This in the original definition. With my definition we'll have

\@memsubfloat{subfigure}[\@empty A][A\unskip]


The \@empty is there for technical reasons, it's not important since that is what will be written in the auxiliary file. The task of \@memsubfloat is also to typeset the subcaption and it basically does

(a)\space A\unskip


where "a" is the "number" (the \unskip isn't there with memoir's definition); if now A is empty, as in your case, the \unskip will kill the \space, otherwise it will do nothing. Bingo!

Of course, if you have captionless subfigures, you won't put subcaptions in the list of figures.

-
If and when you have the time and patience, could you annotate that? I appreciate among experts it's probably obvious, but for us noobs an annotation would be a useful learning resource. If you don't have the time, of course I understand. –  Brent.Longborough Jul 14 '11 at 21:42
Thank you. Excellent explanation. –  Brent.Longborough Jul 15 '11 at 11:53
suggested fix will be added in the next release –  daleif Jul 21 '11 at 8:52