![并排图形绘制中的问题](https://linux22.com/image/411192/%E5%B9%B6%E6%8E%92%E5%9B%BE%E5%BD%A2%E7%BB%98%E5%88%B6%E4%B8%AD%E7%9A%84%E9%97%AE%E9%A2%98.png)
为什么下面的代码不允许并排打印两个图形,而是允许一个图形位于另一个图形的下方?
\begin{figure}[h]
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=1.12\linewidth,height=5.8cm]{Martingale_check_BS_1MLN_iterations.png}
\subcaption{1-year leap}
\label{fig:martingality check BS. 1-year leap}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=1.12\linewidth,height=5.8cm]
{Martingale_check_BS_1MLN_iterations_1monthleap.png}
\subcaption{1-month leap}
\label{fig:martingality check BS. 1-month leap}
\end{subfigure}
\caption{Martingality property check for BS}
\label{fig:Martingality property check for BS}
\end{figure}
这可能取决于两张特定的图像吗?
答案1
两个环境之间有两个连续的换行符subfigure
。这指示 Latex 插入一个新段落。如果您删除空行或注释掉该行,结果将符合预期。
\documentclass{article}
\usepackage{subcaption}
\usepackage{tikz}
\newcommand\dummy{%
\tikz{\draw[fill=green] (0,0) rectangle(\linewidth, 5.8cm);}
}
\begin{document}
\begin{figure}
\begin{subfigure}{0.5\textwidth}
\dummy
\subcaption{1-year leap}
\label{fig:martingality check BS. 1-year leap}
\end{subfigure}%
%
% <---- Comments prevent the insertion of
% a new paragraph with \par
%
\begin{subfigure}{0.5\textwidth}
\dummy
\subcaption{1-month leap}
\label{fig:martingality check BS. 1-month leap}
\end{subfigure}
\caption{Martingality property check for BS}
\label{fig:Martingality property check for BS}
\end{figure}
\end{document}