I am trying to put an image next to an equation and aligning the subcaptions using subcaptionbox. Unfortunately I am having some issues. See the following MWE:

            \subcaptionbox{Plot of example character.\label{fig:original_plot}}{\input{Figures/plot.tex}}
            \subcaptionbox{Format of original data.\label{fig:original_format}}{%
                    X   &=  \{\underbrace{\left[\left(x_{1,1},y_{1,1}\right),\dotsc,\left(x_{1,n_1},y_{1,n_1}\right)\right]}_{\text{stroke 1}}, \\
                        &\qquad     \underbrace{\left[\left(x_{2,1},y_{2,1}\right),\dotsc,\left(x_{2,n_2},y_{2,n_2}\right)\right]}_{\text{stroke 2}},   \\
                        &\qquad     \underbrace{\left[\left(x_{3,1},y_{3,1}\right),\dotsc,\left(x_{3,n_3},y_{3,n_3}\right)\right]}_{\text{stroke 3}}\}

When compiling, I receive the following error:

! Package amsmath Error: \begin{aligned} allowed only in math mode.

See the amsmath package documentation for explanation.
Type  H <return>  for immediate help.

l.33 ^^I^^I^^I}

Any ideas?


1 Answer 1


A \subcaptionbox is essentially a horizontal box, so $$ means just an empty formula.

On the other hand, $$ should never be used in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?

Here's an implementation of your idea:



\begin{figure}[htp] %%% <---- NOT just h



\caption{Plot of example character.\label{fig:original_plot}}
\end{subfigure}% <--- Important!
X = \{ & {\underbrace{[(x_{1,1},y_{1,1}),\dots,(x_{1,n_1},y_{1,n_1})]}_{\text{stroke 1}}}, \\
       & {\underbrace{[(x_{2,1},y_{2,1}),\dots,(x_{2,n_2},y_{2,n_2})]}_{\text{stroke 2}}}, \\
       & {\underbrace{[(x_{3,1},y_{3,1}),\dots,(x_{3,n_3},y_{3,n_3})]}_{\text{stroke 3}}} \}

\caption{Format of original data.\label{fig:original_format}}

\caption{Global caption\label{fig:original}}



Note the removal of all \left and \right, the different alignment point and the braces around \underbrace.

enter image description here

You must log in to answer this question.

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