# Recreate position of subfigures in a table above figure caption

I need to recreate a particular style of captioning a "figure".

Main characteristics of this style are:

• No subcaptions included in the subfigures.
• The position of the subfigures is recreated in a table (using tabular is an option?) above the caption of the figure. I hope the MWE and the picture help to get the idea

Note that the position of the subfigures may follow any type of positioning e.g. in the figure is a 2-2 alignment. Other type of alignment might be 2-2-1, 1-2-2, and so on.

A MWE follows with my work so far. The table can be (obvioulsy) improved. In addition, the table must still be included in the Figure caption starting directly above the letter "F" of "Figure".

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{array}

\newcolumntype{M}{>{\centering\arraybackslash}p{.3cm}}
\renewcommand\arraystretch{1.5}

\usepackage{tikz}
\usepackage[framemethod=default]{mdframed}

\newcommand{\mybox}[1]{
\begin{tikzpicture}
\node[draw,rectangle,line width =0.5pt,text width=0.4cm,
minimum width=0.4cm,minimum height=0.4cm]{#1};
\end{tikzpicture}
}

\begin{document}
\begin{figure}
\centering

\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{example-image-a}
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}
\end{subfigure}

\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-c}
\end{subfigure}

\mybox{a} \mybox{b} \\
\mybox{c}

\caption{TOF depth cameras a) Letter A, b) Letter B and c) Letter C}\label{fig:TOF}

\end{figure}

\end{document}


Any help will be greatly appreciated. You can find an example of such figure in:

-
–  Claudio Fiandrino Jan 17 '13 at 8:14
Thank you Claudio for the edition! –  Marcelino Minero Jan 17 '13 at 17:17

I only needed to make a few changes to your MWE. First, I modified your definition of \mybox to place a strut there to make the baby boxes of uniform height, and I \hfiled around the label so as to center it in the baby box. I also just used a \framebox instead of a tikz box.

I also limited the \centering to the figures themselves, and not the baby boxes. To center-justify but left align and stack the baby box array, I used the stackengine package. I did have to add some \hspace to place it over the word Figure, as in your example.

EDITED to make baby boxes gray.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{array}
\usepackage{stackengine}
\usepackage{xcolor}

\newcolumntype{M}{>{\centering\arraybackslash}p{.3cm}}
\renewcommand\arraystretch{1.5}

\usepackage{tikz}
\usepackage[framemethod=default]{mdframed}
\fboxsep=0pt
\newcommand{\mybox}[1]{\colorbox{lightgray}{%
\framebox[.4cm]{\hfil\strut\textbf{#1}\hfil}%
}}

\begin{document}
\begin{figure}
{\centering
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{example-image-a}
\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}
\end{subfigure}

\begin{subfigure}[b]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-c}
\end{subfigure}

}
~\\\hspace*{1.4em}
\stackunder[0pt]{\mybox{a}\mybox{b}}{\mybox{c}}

\caption{TOF depth cameras a) Letter A, b) Letter B and c) Letter C}\label{fig:TOF}

\end{figure}

\end{document}


And as shown with simple code like this:

\stackunder[0pt]{\mybox{a}\mybox{b}}{\mybox{c}\mybox{d}}
~~~
\def\stackalignment{l}\stackunder[0pt]{\mybox{a}\mybox{b}}{\mybox{c}}
~~~
\belowbaseline[-.75\baselineskip]{\stackanchor[0pt]{\mybox{a}}{\mybox{b}}\mybox{c}}


other stacked box arrangements are easily obtained.

-