Add multilevel caption in figures

floatssubfloats

I am working on overleaf, i need to place images caption like this (highlighted with red pen and blue pen in figure below) separate caption for every image then one caption for two images. The code is given below this code only place captions for two separate imagesenter image description here

    \documentclass{IEEEtran}
    \usepackage{graphicx}
    \usepackage{afterpage}
    \usepackage{multicol}
    \usepackage{lipsum}
    
    \usepackage{subcaption}
    
    \newsavebox{\shortpagebox}
    \newsavebox{\shortpagefigure}
    \begin{document}
      \begin{figure*}
        \centering
        \setkeys{Gin}{width=0.48\linewidth} % <---
    \begin{minipage}{0.48\linewidth}
    \includegraphics{example-image}\hfil
    \includegraphics{example-image}
    
    \caption{fffffffffffffffffffffffffffffffff}
    \label{fig:first}
    \end{minipage}
    \hfill
    \begin{minipage}{0.48\linewidth}
    \includegraphics{example-image}\hfil
    \includegraphics{example-image} 
    
    \caption{fffffffffffffffffffffffffffffffff}
    \label{fig:second}
    \end{minipage}
    
    \bigskip
    \begin{minipage}{0.48\linewidth}
    \includegraphics{example-image}\hfil
    \includegraphics{example-image}
    
    \caption{fffffffffffffffffffffffffffffffff}
    \label{fig:third}
    \end{minipage}
    \hfill
    \begin{minipage}{0.48\linewidth}
    \includegraphics{example-image}\hfil
    \includegraphics{example-image}
    
    \caption{fffffffffffffffffffffffffffffffff}
    \label{fig:fourth}
    \end{minipage}
        \end{figure*}
\end{document}

Best Answer

Since you load the subcaption package, you could use its subfigure environment machinery -- a subfigure is, basically, a minipage environment that's been told what to do if it encounters a \caption directive in its scope -- to achieve your formatting objective.

Two comments:

  • You'll get some warning messages as the caption and subcaption packages aren't fully aware of what the IEEEtran document class can and cannot do. You may ignore these warning messages.

  • The output of the approach proposed here is quite similar to that of Zarko's answer, which isn't surprising as both answers employ the subcaption package. A possibly meaningful difference in the approaches may be that that using subfigure environments rather than \subfloat macros provides a touch more flexibility in terms of vertical positioning of the graphs.

enter image description here

\documentclass{IEEEtran}
\usepackage{graphicx}
\usepackage[skip=0.33\baselineskip]{subcaption}
\begin{document}
\setcounter{figure}{7} % just for this example

\begin{figure*}
\begin{minipage}[t]{\columnwidth}% 1st minipage
\begin{subfigure}[t]{0.475\linewidth}%
    \includegraphics[width=\linewidth]{example-image}
    \caption{CNN with \dots}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.475\linewidth}%
    \includegraphics[width=\linewidth]{example-image}
    \caption{LTSM with \dots}
\end{subfigure}
\caption{The distribution of score}
\label{fig:first}
\end{minipage}%
\hfill
\begin{minipage}[t]{\columnwidth}% 2nd minipage
\begin{subfigure}[t]{0.475\linewidth}%
    \includegraphics[width=\linewidth]{example-image}
    \caption{Rounds vs.\ accuracy}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.475\linewidth}%
    \includegraphics[width=\linewidth]{example-image} 
    \caption{Payment $p$ and score with $N$}
\end{subfigure}
\caption{Training speed and payment with parameter $N$}
\label{fig:second}
\end{minipage}
    
\bigskip\medskip
\begin{minipage}[t]{\columnwidth}% 3rd minipage
\begin{subfigure}[t]{0.475\linewidth}%
    \includegraphics[width=\linewidth]{example-image}
    \caption{Rounds vs.\ accuracy}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.475\linewidth}%
    \includegraphics[width=\linewidth]{example-image}
    \caption{Payment $p$ and score with $K$}
\end{subfigure}
\caption{Training speed and payment with parameter $K$}
\label{fig:third}
\end{minipage}%
\hfill
\begin{minipage}[t]{\columnwidth}% 4th minipage
\begin{subfigure}[t]{0.475\linewidth}%
    \includegraphics[width=\linewidth]{example-image}
    \caption{Training speed with $p$}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.475\linewidth}%
    \includegraphics[width=\linewidth]{example-image} 
    \caption{Proportion of selected node}
\end{subfigure}
\caption{Performance impact of parameter $\psi$}
\label{fig:fourth}
\end{minipage}
\end{figure*}

\end{document}