如何为每种颜色制作一个子图以便每行有 2 个?

如何为每种颜色制作一个子图以便每行有 2 个?

所以我想在子图内再制作一个子图。所以 1 个代表绿色,1 个代表黄色,1 个代表紫色。并且每个颜色内还有 2 个子图。

\begin{figure}
     \centering
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Green.png}
         \caption{Green}
         \label{fig}
     \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Green.png}
         \caption{G}
         \label{fig}
     \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Purple.png}
         \caption{P}
         \label{fig}
     \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Purple_split.png}
         \caption{P}
         \label{fig}
         \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Yellow_unsplit.png}
         \caption{Y}
         \label{fig}
         \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Yellow_split.png}
         \caption{Y}
         \label{fig}
         \end{subfigure}
     \hfill
    \caption{Spectral lines}
    \label{fig:photos}
\end{figure}

答案1

像这样?

在此处输入图片描述

  • 由于所有图像的宽度均相同,因此使用Gin˙keys 来确定其宽度是合理的(这样可以使代码更短)
  • 我会将图像宽度定义为等于subfigure宽度,并subfigure相应地减小宽度,例如0.45\textwidth(或者,0.49\textwidth如果您希望图像稍大一些)
  • 在每行有两张图片之间需要插入空行
\documentclass[a4paper]{article}
\usepackage[demo]{graphicx}  % in real document remove option "demo"
\usepackage[skip=1ex, belowskip=1.5ex]{subcaption}

\begin{document}
    \begin{figure}
\setkeys{Gin}{width=\linewidth}
    \begin{subfigure}[b]{0.45\textwidth}
         \includegraphics{Green_unsplit.png}
         \caption{Green}
         \label{fig:green-unsplit}
     \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.45\textwidth}
         \includegraphics{Green_split.png}
         \caption{Green}
         \label{fig:green-split}
     \end{subfigure}

     \begin{subfigure}[b]{0.45\textwidth}
         \centering
         \includegraphics{Purple_unsplit.png}
         \caption{Purple}
         \label{fig:purple-unsplit}
     \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.45\textwidth}
         \includegraphics{Purple_split.png}
         \caption{Purple split}
         \label{fig:purple-split}
         \end{subfigure}%

     \begin{subfigure}[b]{0.45\textwidth}
         \includegraphics{Yellow_unsplit.png}
         \caption{Yellow }
         \label{fig:yellow-unsplit}
         \end{subfigure}
     \hfill
     \begin{subfigure}[b]{0.45\textwidth}
         \includegraphics{Yellow_split.png}
         \caption{Yellow}
         \label{fig:yellow-split}
      \end{subfigure}

\caption{Spectral line}
\label{fig:photos}
    \end{figure}
\end{document} 

答案2

您的两幅图像比宽,\textwidth因为您有一个尾随空格。使用

\documentclass[a4paper]{scrreprt}

\usepackage[demo]{graphicx}
% customized list environments

\usepackage{subcaption}
% verbatim text, long and colored tables
\begin{document}


\begin{figure}
     \centering
     \begin{subfigure}[b]{0.50\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Green_unsplit.png}
         \caption{Green}
         \label{fig:green-unsplit}
     \end{subfigure}%
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Green_split.png}
         \caption{Green}
         \label{fig:green-split}
     \end{subfigure}%
\hfill
     \begin{subfigure}[b]{0.5\linewidth}
         \centering
         \includegraphics[width=0.6\linewidth]{Purple_unsplit.png}
         \caption{Purple}
         \label{fig:purple-unsplit}
     \end{subfigure}%
     \hfill
     \begin{subfigure}[b]{0.5\linewidth}
         \centering
         \includegraphics[width=0.6\linewidth]{Purple_split.png}
         \caption{Purple split}
         \label{fig:purple-split}
         \end{subfigure}%
     \hfill
     \begin{subfigure}[b]{0.5\linewidth}
         \centering
         \includegraphics[width=0.6\linewidth]{Yellow_unsplit.png}
         \caption{Yellow }
         \label{fig:yellow-unsplit}
         \end{subfigure}%
     \hfill
     \begin{subfigure}[b]{0.5\linewidth}
         \centering
         \includegraphics[width=0.6\linewidth]{Yellow_split.png}
         \caption{Yellow}
         \label{fig:yellow-split}
      \end{subfigure}
     \hfill
    \caption{Spectral line}
    \label{fig:photos}
\end{figure}

\end{document} 

或者使用 0.49 代替 0,5

在此处输入图片描述

答案3

此解决方案\allowbreak在每次之后使用subfigure

\documentclass[a4paper]{article}
\usepackage[demo]{graphicx}  % in real document remove option "demo"
\usepackage[skip=1ex, belowskip=1.5ex]{subcaption}

\begin{document}

\begin{figure}
     \centering
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Green.png}
         \caption{Green}
         \label{fig}
     \end{subfigure}\allowbreak
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Green.png}
         \caption{G}
         \label{fig}
     \end{subfigure}\allowbreak
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Purple.png}
         \caption{P}
         \label{fig}
     \end{subfigure}\allowbreak
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Purple_split.png}
         \caption{P}
         \label{fig}
         \end{subfigure}\allowbreak
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Yellow_unsplit.png}
         \caption{Y}
         \label{fig}
         \end{subfigure}\allowbreak
     \hfill
     \begin{subfigure}[b]{0.5\textwidth}
         \centering
         \includegraphics[width=0.6\textwidth]{Yellow_split.png}
         \caption{Y}
         \label{fig}
         \end{subfigure}
    \caption{Spectral lines}% \caption begins and ends with a \par
    \label{fig:photos}
\end{figure}

\end{document} 

相关内容