我正在尝试将图像放在方程式旁边并使用对齐子标题subcaptionbox
。不幸的是,我遇到了一些问题。请参阅以下 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}
编译时,我收到以下错误:
! 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}
有任何想法吗?
答案1
A\subcaptionbox
本质上是一个水平框,因此$$
仅意味着一个空公式。
另一方面,$$
永远不应该在 LaTeX 中使用,请参阅为什么 \[ ... \] 比 $$ ... $$ 更可取?
以下是您的想法的实现:
\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}
注意删除所有的\left
和\right
、不同的对齐点以及周围的括号\underbrace
。