2

I have the following code to display multiple images:

\begin{figure}[H]
    \centering
    \begin{subfigure}[h]{0.35\textwidth}
        \centering
        \includegraphics[width=\textwidth]{real_time1.eps}
        \caption{{\small Real time image}}    
        \label{fig:real_time1}
    \end{subfigure}
    \hspace{10mm}
    \begin{subfigure}[h]{0.4\textwidth}  
        \centering 
        \includegraphics[width=\textwidth]{real1_plot_MI.eps}
        \caption{{\small Mutual information}}    
        \label{fig:real_time1_MI}
    \end{subfigure}
    \vskip\baselineskip
    \begin{subfigure}[h]{0.4\textwidth}   
        \centering 
        \includegraphics[width=\textwidth]{real1_plot_corr.eps}
        \caption{{\small Pearson correlation coefficient}}    
        \label{fig:real_time1_corr}
    \end{subfigure}
    \hspace{10mm}
    \begin{subfigure}[h]{0.4\textwidth}   
        \centering 
        \includegraphics[width=\textwidth]{real1_plot_SSIM.eps}
        \caption{{\small Structural similarity index}}    
        \label{fig:real_time1_SSIM}
    \end{subfigure}
    \caption{Results comparison for all similarity metrics} 
    \label{fig:all_metrics}
\end{figure}

I want the subfigures to have the following format:

enter image description here

I would also like to have the full caption below detailing each subfigure.

As an example:

Fig. 1.1 (Text) a. (Text) b. (Text)...

I tried a lot of ways but this is not working and most of the time it is a piece of code that requires a lot of modification and I have to do the change to a lot of figures.

Thank you!

3
  • 1
    Welcome. // Unfortunately nobody here can compile your code. It misses: a) the preamble (and related) parts, b) we don't have your images. // Are your images always in the same w*h-format? Not sure about the result you want to have ...
    – MS-SPO
    Commented May 7 at 15:42
  • 2
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented May 7 at 15:43
  • Since you're setting width=\textwidth for each image, the \centering instructions inside the subfigure environments are superfluous. Next, the \small directives for the subfigures' captions are redundant, since that's the default. Third. the h positioning specifiers for subfigure environments are meaningless and are ignored; the only meaningful specifiers are t (top), c (center -- default), and b (bottom). Please fix and streamline your code.
    – Mico
    Commented May 7 at 16:27

2 Answers 2

3

This uses the fact that the "short caption" is accesible using \nameref. \floatsep is the distance what would be placed between two figures. It looks slightly lopsided, but that is an optical illusion.

\documentclass{article}
\usepackage[export]{adjustbox}% for valign
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{hyperref}% for \nameref

\captionsetup[subfigure]{position=above, singlelinecheck=false}
\captionsetup[figure]{subrefformat=parens}

\newcommand{\myref}[1]{\subref*{#1}~\nameref*{#1}}

\begin{document}
\begin{figure}[ht]
    \centering
    \begin{subfigure}[t]{1.5em}
        \caption[Real time image]{}
        \label{fig:real_time1}
    \end{subfigure}%
    \begin{subfigure}[t]{0.4\textwidth}
        \includegraphics[width=\textwidth, valign=T]{example-image-a}
    \end{subfigure}\hfil
    \begin{subfigure}[t]{1.5em}
        \caption[Mutual information]{}
        \label{fig:real_time1_MI}
    \end{subfigure}%
    \begin{subfigure}[t]{0.4\textwidth}  
        \includegraphics[width=\textwidth, valign=T]{example-image-b}
    \end{subfigure}
    
    \vskip\floatsep
    \begin{subfigure}[t]{1.5em}
        \caption[Pearson correlation coefficient]{}
        \label{fig:real_time1_corr}
    \end{subfigure}%
    \begin{subfigure}[t]{0.4\textwidth}
        \includegraphics[width=\textwidth, valign=T]{example-image-c}
    \end{subfigure}\hfil
    \begin{subfigure}[t]{1.5em}
        \caption[Structural similarity index]{}
        \label{fig:real_time1_SSIM}
    \end{subfigure}%
    \begin{subfigure}[t]{0.4\textwidth}  
        \includegraphics[width=\textwidth, valign=T]{example-image}
    \end{subfigure}
    
    \caption{Results comparison for all similarity metrics.
      \myref{fig:real_time1}
      \myref{fig:real_time1_MI}
      \myref{fig:real_time1_corr}
      \myref{fig:real_time1_SSIM}
    }
    \label{fig:all_metrics}
\end{figure}
\end{document}

demo

3

I don't think you need subfigure for this job.

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{booktabs}

\begin{document}

\begin{figure}[htp]
\centering

\begin{tabular}{@{} r @{\hspace{3pt}} c r @{\hspace{3pt}} c @{}}
A & \includegraphics[width=0.4\textwidth,valign=t]{example-image} &
B & \includegraphics[width=0.4\textwidth,valign=t]{example-image} \\
\addlinespace[3\tabcolsep]
C & \includegraphics[width=0.4\textwidth,valign=t]{example-image} &
D & \includegraphics[width=0.4\textwidth,valign=t]{example-image} \\
\end{tabular}

\caption[Results comparison for all similarity metrics]{%
  Results comparison for all similarity metrics;
  (A)~shows Real time image;
  (B)~shows Mutual information;
  (C)~shows Pearson correlation coefficient;
  (D)~shows Structural similarity index}
\label{fig:all_metrics}

\end{figure}

\end{document}

I used the optional argument to \caption for the short caption to be printed in the table of contents.

enter image description here

By the way, such a large figure environment should not be given the [H] option (actually none should) that just makes typesetting awkward.

There is no [h] option to subfigure.

You can also use \ref.

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{booktabs}
\usepackage{subcaption}

\newcommand{\fakesubfigure}[1]{%
  \refstepcounter{subfigure}%
  \makebox[1em][r]{\thesubfigure\hspace{3pt}}%
  #1%
}

\begin{document}

\begin{figure}[htp]
\centering
\labelformat{subfigure}{(#1)}

\begin{tabular}{@{} c c @{}}
\fakesubfigure{%
  \includegraphics[width=0.4\textwidth,valign=t]{example-image}%
  \label{fig:real_time1}%
} &
\fakesubfigure{%
  \includegraphics[width=0.4\textwidth,valign=t]{example-image}%
  \label{fig:real_time1_MI}%
} \\
\addlinespace[3\tabcolsep]
\fakesubfigure{%
  \includegraphics[width=0.4\textwidth,valign=t]{example-image}%
  \label{fig:real_time1_corr}%
} &
\fakesubfigure{%
  \includegraphics[width=0.4\textwidth,valign=t]{example-image}%
  \label{fig:real_time1_SSIM}%
}
\end{tabular}

\caption[Results comparison for all similarity metrics]{%
  Results comparison for all similarity metrics;
  \ref{fig:real_time1}~Real time image;
  \ref{fig:real_time1_MI}~Mutual information;
  \ref{fig:real_time1_corr}~Pearson correlation coefficient;
  \ref{fig:real_time1_SSIM}~Structural similarity index}
\label{fig:all_metrics}

\end{figure}

\end{document}

enter image description here

2
  • Thank you so much for your answer it was really helpful. But in this case, can I label each figure and reference them in later paragraphs?
    – Roy Turk
    Commented May 9 at 7:11
  • @RoyTurk See update.
    – egreg
    Commented May 9 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .