并排比较两个图表

并排比较两个图表

我正在尝试并排比较两个 PDF 格式的图表。我有这篇文章 -两个并排的身影得到一些提示。

这是我想出的代码。

\begin{figure}
\begin{minipage}[t]{0.45\linewidth}
\includegraphics[scale=0.30]{before.pdf}
\caption{(a) Before}
\end{minipage}%

\hfill\vrule\hfill
\begin{minipage}[t]{0.45\linewidth}
\includegraphics[scale=0.3]{after.pdf}
\caption{(b) After}
\end{minipage}%
\caption{Hello}
\end{figure}

这就是结果,这与我预期的并不完全一致。

在此处输入图片描述

  • 需要做哪些修改才能使图片并排放置?
  • 我只想要标题 (a) 之前和 (b) 之后,不带任何Figure前缀。我应该怎么做?

答案1

虽然您可以使用 完美地解决问题minipages,但对于标题用字母 (a、b、..) 枚举的子图,您也可以使用包subcaption来简化一些代码,因为您不需要写“(a)”和“(b)”,但主要是因为您可以使用此包灵活地列出子图。请注意,在 MWE 中既不需要使用\centering也不需要包含文件扩展名 (.pdf)。

注意:删除包demo中的选项graphicx以使用图表而不是黑框:

\documentclass{article}
\usepackage[demo]{graphicx} % remove option for real images
\usepackage[list=true]{subcaption}

\begin{document}
\listoffigures    
\vspace{3cm}

\begin{figure}[h]%

\begin{subfigure}[h]{0.4\textwidth}
\includegraphics[width=\textwidth]{before}
\caption{Before}
\end{subfigure}
\hfill\vrule\hfill
\begin{subfigure}[h]{0.4\textwidth}
\includegraphics[width=\textwidth]{after}
\caption{After}
\end{subfigure}%

\caption[Hello]{Hello, this a minimal working example}
\end{figure}
\end{document}

在此处输入图片描述

出于同样的原因, 您也可以使用subfig或包。请参阅subfigure设置子图之间的默认距离作为这些包的示例。

答案2

感谢 egreg 和 Vincent,我能够做出更正。问题在于空行导致对齐错误,我将其替换captioncentering以删除Figure

在此处输入图片描述

\begin{figure}
\begin{minipage}[t]{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{before.pdf}

(a) Before
\end{minipage}%
\hfill\vrule\hfill
\begin{minipage}[t]{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{after.pdf}

(b) After
\end{minipage}
\caption{Hello}
\end{figure}

相关内容