如何将子图合并为一个

如何将子图合并为一个

我的标题分别显示了我的所有图形。我希望它们都成为一张图的一部分。以下是代码(它是从另一个答案中逐字复制的,尽管我确实花了相当多的时间自己解决这个问题)-

\documentclass{article}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}
\minipage{0.2\textwidth}
  \centering
  \includegraphics[width=\linewidth]{Environment1.png}
  \caption{}
  \label{fig:env}
\endminipage\hfill
\minipage{0.2\textwidth}
  \centering
  \includegraphics[width=\linewidth]{Environment2.png}
  \caption{}
  \label{fig:galaxy}
\endminipage\hfill
% <-- GET RID OF PARAGRAPH BREAK
\minipage{0.2\textwidth}%
  \centering
  \includegraphics[width=\linewidth]{Environment3.png}
  \caption{}
  \label{}
\endminipage\hfill% <--PROBABLY WANT AN \hfill
\minipage{0.2\textwidth}%
  \centering
  \includegraphics[width=\linewidth]{Environment4.png}
  \caption{}
  \label{}
\endminipage
\caption{Stuff}
\label{Environment_2}
\end{figure}

\end{document}

在此处输入图片描述

我只想要标题 a、b、c 和 d,而不是图 1、2、3 和 4。

答案1

借助软件包subcaption,而subfigure不是minipage

在此处输入图片描述

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}{0.2\textwidth}
  \centering
  \includegraphics[width=\linewidth]{Environment1.png}
  \caption{}
  \label{fig:env}
\end{subfigure}\hfill
\begin{subfigure}{0.2\textwidth}
  \centering
  \includegraphics[width=\linewidth]{Environment2.png}
  \caption{}
  \label{fig:galaxy}
\end{subfigure}\hfill
\begin{subfigure}{0.2\textwidth}
  \centering
  \includegraphics[width=\linewidth]{Environment3.png}
  \caption{}
  \label{}
\end{subfigure}\hfill
\begin{subfigure}{0.2\textwidth}
  \centering
  \includegraphics[width=\linewidth]{Environment4.png}
  \caption{}
  \label{}
\end{subfigure}
\caption{Stuff}
\label{Environment_2}
\end{figure}

\end{document}

答案2

使用 时代码更短(与和floatrow配合):captionsubcaption

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption, subcaption, floatrow}

\begin{document}

\begin{figure}
\ffigbox{\begin{subfloatrow}[4]
  \centering
\ffigbox{\includegraphics[width=0.2\textwidth]{Environment1.png}}
 {\caption{} \label{fig:env}}
\ffigbox{\includegraphics[width=0.2\textwidth]{Environment2.png}}
  {\caption{} \label{fig:galaxy}}
\ffigbox{\includegraphics[width=0.2\textwidth]{Environment3.png}}
{\caption{}\label{}}
\ffigbox{\includegraphics[width=0.2\textwidth]{Environment4.png}}
{\caption{}\label{sfig}}
\end{subfloatrow}}
{\caption{Stuff}\label{Environment_2}}
\end{figure}

\end{document} 

在此处输入图片描述

相关内容