[Tex/LaTex] Subcaption of figures in a table

subcaptionsubfloatstablestabularx

There are two ways I would like to describe the figures in the table: put sub caption under each figure (preferred) or insert the description directly in the figure.

To create a table of figures, I wrote the following code:

\begin{sidewaystable}[!htbp]
\label{tab:gr}
\centering\small\setlength\tabcolsep{2pt}
\begin{tabularx}{\textwidth}{@{}>{\bfseries}c*{9}{X}@{}}

  \includegraphics[width=2.2in,height=1.8in]{A1}&
  \includegraphics[width=2.2in,height=1.8in]{A2} & 
  \includegraphics[width=2.2in,height=1.8in]{A3} & 
  \includegraphics[width=2.2in,height=1.8in]{A4} \\

  \includegraphics[width=2.2in,height=1.8in]{B1} &
  \includegraphics[width=2.2in,height=1.8in]{B2} &
  \includegraphics[width=2.2in,height=1.8in]{B3} &
  \includegraphics[width=2.2in,height=1.8in]{B4} \\

  \includegraphics[width=2.2in,height=1.8in]{fig/C1} &
  \includegraphics[width=2.2in,height=1.8in]{fig/C2} &
  \includegraphics[width=2.2in,height=1.8in]{fig/C3} &
  \includegraphics[width=2.2in,height=1.8in]{fig/C4} \\

  \includegraphics[width=2.2in,height=1.8in]{fig/D1} &
  \includegraphics[width=2.2in,height=1.8in]{fig/D2} &
  \includegraphics[width=2.2in,height=1.8in]{fig/D3} &
  \includegraphics[width=2.2in,height=1.8in]{fig/D4} \\
  \end{tabularx}
  \caption{The main caption of the table.}
\end{sidewaystable}

Because I got different meanings of figures given a row, I want to put individual description under (right to, in this case) each figure.

Best Answer

You can use the \subcaption command from the package with the same name to add a caption for each sufigure.

There is a problem with using subcaptions inside a tabularx, see this bug report at SourceForge, so it's better to use a regular tabular with p columns.

Notes about the code:

  • The \label always has to be placed after (or within) the \caption.
  • I reduced the size of the images a bit, they need to be smaller to be able to fit in the page, due to the extra space added by the subcaptions. (Even with my adjustment the table may wider than the text block, depending on your settings.)
  • A space between the image and the subcaption seems to introduce extra vertical spacing. I.e., instead of

    \includegraphics[width=1.8in,height=1.2in]{example-image} \subcaption{Text}
    

    write

    \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text}
    
  • To further compress the table vertically, you can add \renewcommand\arraystretch{0} right before the tabular. You can also move the subcaption closer to the images with \captionsetup[subtable]{aboveskip=2pt}. These are in the code, but commented.


\documentclass{article}
\usepackage{graphicx}
\usepackage{rotating}    
\usepackage{subcaption}
\begin{document}
\begin{sidewaystable}
\centering\small\setlength\tabcolsep{2pt}%
%\renewcommand\arraystretch{0}
%\captionsetup[subtable]{aboveskip=2pt}
\begin{tabular}{@{}*{4}{p{1.8in}}@{}}
  \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-a}\subcaption{Text} & 
  \includegraphics[width=1.8in,height=1.2in]{example-image-b}\subcaption{Text} & 
  \includegraphics[width=1.8in,height=1.2in]{example-image-c}\subcaption{Text} \\

  \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-a}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-b}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-c}\subcaption{Text} \\

  \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-a}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-b}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-c}\subcaption{Text} \\

  \includegraphics[width=1.8in,height=1.2in]{example-image}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-a}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-b}\subcaption{Text} &
  \includegraphics[width=1.8in,height=1.2in]{example-image-c}\subcaption{Text} \\
  \end{tabular}
  \caption{The main caption of the table.}
\label{tab:gr}
\end{sidewaystable}
\end{document}