将图片和标题并排放置

将图片和标题并排放置

我想将前 2 个数字并排放置,将接下来的 3 个数字放在下一行,将最后一个数字放在第三行。这是我的代码:

\begin{figure}
\centering
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=.4\linewidth]{orign.png}
\caption{Image after preprocessing}
\end{minipage}%

\begin{minipage}{.5\textwidth}
\includegraphics[width=.4\linewidth]{labeled.png}
\caption{Image labeled by cluster index}
\end{minipage}%

\begin{minipage}{.5\textwidth}
\centering
\includegraphics[ width=\linewidth]{3c.png}
\caption{The 3 clusters}
\end{minipage}%

\begin{minipage}{.5\textwidth}
\centering
\includegraphics[height=3cm, width=3cm]{infect.png}
\caption{Infected segment distinguished}
\end{minipage}%
\end{figure}

我的结果是

在此处输入图片描述

但我想要的是

在此处输入图片描述

答案1

像这样吗?

在此处输入图片描述

环境minipage主要用于限制字幕的宽度与相关图像的宽度相等。

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\begin{document}
\begin{figure}[ht!]
\captionsetup{skip=0.25\baselineskip}
\hfill
\begin{minipage}{0.3\textwidth}
\includegraphics[width=\linewidth]{orign.png}
\caption{Image after preprocessing}
\end{minipage}
\hfill
\begin{minipage}{0.3\linewidth}
\includegraphics[width=\linewidth]{labeled.png}
\caption{Image labeled by cluster index}
\end{minipage}
\hfill\null

\bigskip
\includegraphics[width=0.3\linewidth]{3a.png}\hfill
\includegraphics[width=0.3\linewidth]{3b.png}\hfill
\includegraphics[width=0.3\linewidth]{3c.png}
\caption{The 3 clusters}

\bigskip
\hfill
\begin{minipage}{0.3\linewidth}
\includegraphics[width=\linewidth]{infect.png}
\caption{Infected segment distinguished}
\end{minipage}
\hfill\null
\end{figure}
\end{document}

答案2

如果你想将多张图片合并成一张图,我建议子字幕包

\documentclass{article}
\usepackage{subcaption}

\begin{document}
\begin{figure}
    \centering
    \begin{minipage}[b]{.3\linewidth}
        \centering
        %\includegraphics[width=\linewidth]{orign.png}]
        \rule{\linewidth}{\linewidth}
        \subcaption{Image after preprocessing}
        %TODO: \label
    \end{minipage}%
    \qquad
    \begin{minipage}[b]{.3\linewidth}
        %\includegraphics[width=\linewidth]{labeled.png}
        \rule{\linewidth}{\linewidth}
        \subcaption{Image labeled by cluster index}
        %TODO: \label
    \end{minipage}%
    \medskip

    \begin{minipage}{\linewidth}
        \centering
        %\includegraphics[ width=\linewidth]{3c.png}
        \rule{.3\linewidth}{.3\linewidth}%
        \quad
        \rule{.3\linewidth}{.3\linewidth}%
        \quad
        \rule{.3\linewidth}{.3\linewidth}%
        \subcaption{The 3 clusters}
        %TODO: \label
    \end{minipage}%
    \medskip

    \begin{minipage}{\linewidth}
        \centering
        %\includegraphics[height=3cm, width=3cm]{infect.png}
        \rule{.3\linewidth}{.3\linewidth}
        \subcaption{Infected segment distinguished}
        %TODO: \label
    \end{minipage}%

    \caption{The entire process}
    %TODO: \label
\end{figure}
\end{document}

截屏

相关内容