1

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:

\begin{figure}[h]
    \begin{subfigure}{0.5\textwidth}
        \centering
            \subcaptionbox{Plot of example character.\label{fig:original_plot}}{\input{Figures/plot.tex}}
    \end{subfigure}
    ~
    \begin{subfigure}{0.5\textwidth}
        \centering
            \subcaptionbox{Format of original data.\label{fig:original_format}}{%
                $$
                \begin{aligned}
                    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}}\}
                \end{aligned}
                $$%
            }
    \end{subfigure}
    \caption{.....}
    \label{fig:original}
\end{figure}

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?

2

1 Answer 1

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:

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

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

\begin{subfigure}[b]{0.5\textwidth}
\centering

\includegraphics[width=.8\linewidth]{example-image}

\caption{Plot of example character.\label{fig:original_plot}}
\end{subfigure}% <--- Important!
\begin{subfigure}[b]{0.5\textwidth}
\centering
\begin{align*}
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}}} \}
\end{align*}

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

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

\end{figure}

\end{document}

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 .