# Problem with figure using subfloat and amsmath align

I'm trying to use package subfig and amsmath align (in order to align equations) inside the subfloat block. Are there any incompatibilities or am I doing something wrong? Details follow. This is my problem, my code:

\begin{figure}
\centering
\subfloat[First]{
\begin{align*}
ciao &= 2\\
ciao &= 3
\end{align*}}
\subfloat[First]{
\begin{align*}
ciao &= 2\\
ciao &= 3
\end{align*}}
\end{figure}


I get the error (in ShareLatex)

Missing \endgroup inserted.

\endgroup l.374 \end{align*}} I've inserted something that you may have forgotten. (See the above.) With luck, this will get me unwedged. But if you really didn't forget anything, try typing 2' now; then my insertion and my current dilemma will both disappear.

This code (used inside subfloat)... :

\begin{align*}
ciao &= 2\\
ciao &= 3
\end{align*}


...but moved out of the subfigure is working just fine.

Also the figure with plain text inside the subfloat[]{} works without errors. (I have only a warning for underfull \hbox, I don't know what does it means but I think "there is simply not so much inside the figure")

Any tip is appreciated. Regards

• Maybe \begin{aligned} instead of \begin{align*} and the closing with \end{aligned} – egreg Nov 1 '16 at 11:15
• It seems to work well, thankyou. I didn't know about alignement in math mode. I'll try with more complex expressions and I'll update the post with you answer in case. It would be useful to figure out if this is a subfig/asmath incompatibility or a bug. – Fabiano Tarlao Nov 1 '16 at 11:24

This is not really related to \subfloat; you would get into the same problem with

\mbox{\begin{align*}...\end{align*}}


Also something like

\subfloat[Label]{%
This is paragraph one.

This is paragraph two.
}


would not produce two paragraphs. The reason is that for making paragraphs TeX needs to know the line width, which is not set when making a horizontal box. A \subfloat is processed in a horizontal box as well.

You can get around this by using an inline formula

\subfloat[First]{% <-- don't forget
\begin{aligned} ciao &= 2\\ ciao &= 3 \end{aligned}}

• I appreciate a lot explanation of inner workings. Thank you – Fabiano Tarlao Nov 1 '16 at 11:39
• Appears to apply also to the subfigure package. Is this why subcaption is recommended over them and it requires specifying the line width? – Blaisorblade Feb 24 '17 at 17:07
• @Blaisorblade subfigure has been obsolete for at least 15 years and subfig has replaced it; however, subcaption` (albeit with a different syntax) has many more features. – egreg Feb 24 '17 at 17:10