4

I could achieve the following using figure and table:

enter image description here

And using some multiline alignment I can align the "captions" (which is actually text) to the center:

enter image description here

However I'd like to be able to refer to each row using \ref, therefore I need each row to be a subfigure, with the caption on the left, without the word "Figure".
How can it be achieved?

This is the code I used so far, using a table:

\begin{figure}[ht]
\centering
\par%
\begin{tabular}{ccc}
& RGB & NIR\\
(a) & \includegraphics[width=.3\linewidth]{whatever.jpg} & \includegraphics[width=.3\linewidth]{whatever.jpg}\\
(b) & \includegraphics[width=.3\linewidth]{whatever.jpg} & \includegraphics[width=.3\linewidth]{whatever.jpg}\\
(c) & \includegraphics[width=.3\linewidth]{whatever.jpg} & \includegraphics[width=.3\linewidth]{whatever.jpg}\\
(d) & \includegraphics[width=.3\linewidth]{whatever.jpg} & \includegraphics[width=.3\linewidth]{whatever.jpg}\\
\end{tabular}
\caption{some caption}.}%
\label{fig:fig1}%
\end{figure}

I also managed to do a figure of subfigures, but the captions appeared in the bottom.

2
  • Please show the code you've tried so far.
    – Mico
    Commented Mar 7, 2021 at 12:01
  • Added the code.
    – Jjang
    Commented Mar 7, 2021 at 12:46

3 Answers 3

5

The following sample code should get you started.

enter image description here

\documentclass{article}
\usepackage{array,booktabs}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}} % w/ horizontal centering
\usepackage{subcaption} % for 'subfigure' environment
\usepackage[demo]{graphicx}

\begin{document}
\begin{figure}[ht!]
\setlength\tabcolsep{3pt} % default: 6pt
\centering
\begin{tabular}{@{} r M{0.3\linewidth} M{0.3\linewidth} @{}}
& RGB & NIR\\
\begin{subfigure}{0.05\linewidth} \caption{}\label{subfig:a} \end{subfigure} 
  & \includegraphics[width=\hsize]{whatever.jpg} 
  & \includegraphics[width=\hsize]{whatever.jpg}\\ \addlinespace
\begin{subfigure}{0.05\linewidth} \caption{}\label{subfig:b} \end{subfigure} 
  & \includegraphics[width=\hsize]{whatever.jpg}    
  & \includegraphics[width=\hsize]{whatever.jpg}\\ \addlinespace
\begin{subfigure}{0.05\linewidth} \caption{}\label{subfig:c} \end{subfigure} 
  & \includegraphics[width=\hsize]{whatever.jpg} 
  & \includegraphics[width=\hsize]{whatever.jpg}\\ \addlinespace
\begin{subfigure}{0.05\linewidth} \caption{}\label{subfig:d} \end{subfigure} 
  & \includegraphics[width=\hsize]{whatever.jpg} 
  & \includegraphics[width=\hsize]{whatever.jpg}\\
\end{tabular}
\caption{Four rows of graphs}
\label{fig:fig1}
\end{figure}

\noindent
Cross-references to subfigures \ref{subfig:a} and \ref{subfig:d}.
\end{document}
2
  • To see if I understood your answer (not OP): yo have created a table with three columns, in which the first column has a minimal width and whose only function is to "create" the (a), (b)... as well as the label to refer to it. Is that it? It's a very clever solution.
    – Jes
    Commented Mar 7, 2021 at 14:33
  • 1
    @Jes - That's exactly right. If I had started from scratch, I might have pursued a different approach. However, I thought it would be useful to build on the the OP's initial code.
    – Mico
    Commented Mar 7, 2021 at 15:01
5

The original idea was to use \subcaption in the first column, but its baseline is at the top making vertical alignment difficult. And yes, you can use \label with \tabcaption.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}% or \newcounter{subfigure}[figure]
\usepackage{duckuments}% just for fun
\usepackage{array}

\newcolumntype{v}{>{\sbox0\bgroup}c<{\egroup\raisebox{\dimexpr 0.5\dp0-0.5\ht0}%
 [\dimexpr 0.5\ht0-0.5\dp0+1pt][\dimexpr 0.5\ht0-0.5\dp0+1pt]{\usebox0}}}

\newcommand{\tabcaption}{\refstepcounter{subfigure}(\thesubfigure)}

\begin{document}

\begin{figure}[ht]
\centering

\begin{tabular}{vvv}
& RGB & NIR\\
\tabcaption & \includegraphics[width=.3\linewidth]{example-image-duck}
            & \includegraphics[width=.3\linewidth]{example-image-duck}\\
\tabcaption & \includegraphics[width=.3\linewidth]{example-image-duck}
            & \includegraphics[width=.3\linewidth]{example-image-duck}\\
\tabcaption & \includegraphics[width=.3\linewidth]{example-image-duck}
            & \includegraphics[width=.3\linewidth]{example-image-duck}\\
\tabcaption & \includegraphics[width=.3\linewidth]{example-image-duck}
            & \includegraphics[width=.3\linewidth]{example-image-duck}
\end{tabular}
\caption{some caption}% note: \caption begins and ends with a \par
\label{fig:fig1}
\end{figure}

\end{document}

demo

4

With use of the floatrow and subfig packages:

\documentclass{article}
\usepackage{graphicx}
\usepackage{floatrow}
\usepackage[label font=bf, labelformat=simple]{subfig}
\floatsetup[figure]{style=plain,subcapbesideposition=center}

\begin{document}
%---------------------------------------------------------------%
    \begin{figure}
    \centering
\setkeys{Gin}{width=0.45\textwidth}
    \quad\parbox{0.45\linewidth}{\hfil RGB} \parbox{0.45\linewidth}{\hfil NIR}  
    
    \smallskip 
\sidesubfloat[\label{fig:a}]%
    {\includegraphics{example-image-duck}
        \hfil
     \includegraphics{example-image-duck}
    }

\medskip
\sidesubfloat[\label{fig:b}]%
    {\includegraphics{example-image-duck}
        \hfil
     \includegraphics{example-image-duck}
    }

\medskip
\sidesubfloat[\label{fig:b}]%
    {\includegraphics{example-image-duck}
        \hfil
     \includegraphics{example-image-duck}
    }
    \caption{main caption}
\label{fig:myfigure}
    \end{figure}
\end{document}

enter image description here

5
  • What if I wanted to add text at the bottom of each of the duck figures? I tried including the includegraphics inside the subfloat, but this creates and moves the counter. Commented Sep 4, 2022 at 14:19
  • did you mean with your solution? I do not see a table here. However, it works with John Kormylo's solution. Commented Sep 4, 2022 at 14:28
  • @user3236841, in image insert (below row of images in \sidesubfloat) rows of \parboxes with desired texts.
    – Zarko
    Commented Sep 4, 2022 at 14:33
  • using \parbox, how do I center each text under each duck? Commented Sep 4, 2022 at 14:40
  • @user3236841, on the same way as is done in the first "row" with \parboxses.
    – Zarko
    Commented Sep 4, 2022 at 17:08

You must log in to answer this question.

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