4 张图片中有 1 张图片未完全对齐

4 张图片中有 1 张图片未完全对齐

刚接触 LaTeX。我用 4 幅 2x2 网格格式的图片制作了一个图形,尽管代码相同,但其中一张图片与其他图片不对齐。为了确认不是图片的问题,我尝试交换其他图片,但右上方的图片总是向右倾斜。这不是一个惊天动地的问题,但很烦人,因为我的其他图形在图形中彼此完美对齐。

我目前的代码:

\begin{figure}[htbp]
\begin{subfigure}[b]{0.48\linewidth}        
    \centering
    \includegraphics[width=\linewidth]{Sample A SEM micrograph.png}
    \caption{sample A SEM micrograph}
    \label{fig:A SEM}
\end{subfigure}
\begin{subfigure}[b]{0.48\linewidth}     
    \centering
    \includegraphics[width=\linewidth]{Sample B SEM micrograph.png}
    \caption{sample B SEM micrograph}
    \label{fig:B SEM}
\end{subfigure}
\begin{subfigure}[b]{0.48\linewidth}   
    \centering
    \includegraphics[width=\linewidth]{Sample C SEM micrograph.png}
    \caption{sample C SEM micrograph}
    \label{fig:C SEM}
\end{subfigure}
\begin{subfigure}[b]{0.48\linewidth}       
    \centering
    \includegraphics[width=\linewidth]{Sample D SEM micrograph.png}
    \caption{sample D SEM micrograph}
    \label{fig:D SEM}
\end{subfigure}
\caption{comparison of SEM micrographs for all the samples}
\label{fig:SEMimages}
\end{figure}

由于某种原因,图像 B(样本 B SEM 显微照片)被挤压到右侧。

]]1

这些图像都是相同的尺寸,所以我不确定是什么原因造成的。如能提供任何帮助我将不胜感激。

答案1

正如@UlrikeFischer 在评论中提到的,如果在四个subfigure环境中的第二个环境后插入一个空行,不均匀空白问题就会消失。然而,这样做的代价是subfigure环境对之间现在几乎没有任何水平分隔。补救措施是什么?插入几个\hfill指令。而且,一定要在第二行图像之前插入一个分隔符指令,例如\bigskip\medskip,以澄清子标题 (a) 和 (b) 属于哪个图表。

顺便说一句,这四个\centering指令都不需要。我会将它们注释掉——或者直接删除它们。

在此处输入图片描述

\documentclass[demo]{article}  % remove 'demo' option in real doc.

\usepackage{subcaption,graphicx}

\begin{document}
\begin{figure}[htbp]
\begin{subfigure}[b]{0.48\linewidth}        
    %\centering
    \includegraphics[width=\linewidth]{Sample A SEM micrograph.png}
    \caption{sample A SEM micrograph}
    \label{fig:A SEM}
\end{subfigure}\hfill % <-- new
\begin{subfigure}[b]{0.48\linewidth}     
    %\centering
    \includegraphics[width=\linewidth]{Sample B SEM micrograph.png}
    \caption{sample B SEM micrograph}
    \label{fig:B SEM}
\end{subfigure} % new: next line is blank

\bigskip % <-- new
\begin{subfigure}[b]{0.48\linewidth}   
    %\centering
    \includegraphics[width=\linewidth]{Sample C SEM micrograph.png}
    \caption{sample C SEM micrograph}
    \label{fig:C SEM}
\end{subfigure}\hfill % <-- new
\begin{subfigure}[b]{0.48\linewidth}       
    %\centering
    \includegraphics[width=\linewidth]{Sample D SEM micrograph.png}
    \caption{sample D SEM micrograph}
    \label{fig:D SEM}
\end{subfigure}

\caption{comparison of SEM micrographs for all the samples}
\label{fig:SEMimages}
\end{figure}

\end{document}

相关内容