两个子图对应一个子标题

两个子图对应一个子标题

我有以下代码,它为每个子图输出一个子标题:

\begin{figure}[]
  \centering
  \subcaptionbox{image 1}%
    {\includegraphics{image1.png}\hspace{0.5cm}
  \subcaptionbox{image 2}%
    {\includegraphics{image2.png}}%

\bigskip

  \subcaptionbox{image 3}}%
    {\includegraphics{image3.png}}\hspace{0.5cm}
  \subcaptionbox{image 4}%
    {\includegraphics{image4.png}}%
  \caption{Four images.}
\end{figure}

是否可以修改它以便为图像 1 和 2 设置一个子标题,为图像 3 和 4 设置另一个子标题?

答案1

是的,每个只需放置两张图片\subcaptionbox

在此处输入图片描述

\documentclass{article}
\usepackage[demo]{graphicx} % the demo option replace images with black boxes
\usepackage{subcaption}
\begin{document}
\begin{figure}
  \centering
  \subcaptionbox{image 1 and 2}%
    {\includegraphics{image1.png}\hspace{0.5cm}\includegraphics{image2.png}}%

\bigskip

  \subcaptionbox{image 3 and 4}%
    {\includegraphics{image3.png}\hspace{0.5cm}\includegraphics{image4.png}}%
  \caption{Four images.}
\end{figure}
\end{document}

答案2

我认为更简单的方法是启动子图环境并将标题放在第一和第二个图像之后,而不是制作子标题框。

\begin{figure}[h]
  \centering
  \begin{subfigure}{\textwidth}
        \includegraphics[width=0.49\textwidth]{image1.png}
        \hspace{1cm}
        \includegraphics[width=0.49\textwidth]{image2.png}
        \caption{Image 1 and 2}
        \label{fig:1-2}
  \end{subfigure}
 \hspace{0.5cm}
  \begin{subfigure}{\textwidth}
        \includegraphics[width=0.49\textwidth]{image3.png}
        \hspace{1cm}
        \includegraphics[width=0.49\textwidth]{image4.png}
        \caption{Image 3 and 4}
        \label{fig:3-4}
  \end{subfigure}
\end{figure}

相关内容