[Tex/LaTex] Align environment {amsmath} inside subfigure {subcaption} breaks figure numbering

amsmathnumberingsubcaption

When I put an equation in align environment into a subfigure, it breaks figure numbering. In the example below, the whole figure gets number 2, not 1 as I want.

How do I fix it?

\begin{figure}
\begin{subfigure}[b]{.6\linewidth}
\centering
% array* or flalign or similar here breaks numbering
\begin{flalign*}
a& = b \\
c& = d
\end{flalign*}
\subcaption{\label{fig:tb}}
\end{subfigure}%
\caption{\label{fig:toffoli}Toffoli gate.}
\end{figure}

The example can be viewed at https://www.writelatex.com/read/xkhkknjnfvdq .

Best Answer

You can solve this by using

\[ \begin{aligned}
     %your equations
\end{aligned} \]

Here is a slight modification of your example: https://www.writelatex.com/read/gtnsxqnpkdtr