并排图形绘制中的问题

并排图形绘制中的问题

为什么下面的代码不允许并排打印两个图形,而是允许一个图形位于另一个图形的下方?

\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}

相关内容