# Grid of images with captions as column name

I am new to latex. I want to create exactly similar grid as shown in image below except I want 'ground truth', 'baseline' and 'proposed' text on top. Can I refer single images from grid elsewhere? I am using overleaf environment.

• welcome to tex.se! what you try so far? can you show this in form of small but complete document (minimal working example)? – Zarko Sep 27 '18 at 14:43
• sorry that I did not have any clue about grouping and I am using template provided by university so MWE would be difficult. – abdul qayyum Sep 27 '18 at 15:08
• well, than it may happens, that answers will not fit to your document ... – Zarko Sep 27 '18 at 15:16

There are quite a few ways you could accomplish this. You could use a tabular environment. But the first approach I'll show you is using TikZ

Code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[picture format/.style={inner sep=2pt,}]

\node[picture format]                   (A1)               {\includegraphics[width=1in]{images/oak_tree}};
\node[picture format,anchor=north]      (B1) at (A1.south) {\includegraphics[width=1in]{images/restaurant}};

\node[picture format,anchor=north west] (A2) at (A1.north east) {\includegraphics[width=1in]{images/oak_tree}};
\node[picture format,anchor=north]      (B2) at (A2.south)      {\includegraphics[width=1in]{images/restaurant}};

\node[picture format,anchor=north west] (A3) at (A2.north east) {\includegraphics[width=1in]{images/oak_tree}};
\node[picture format,anchor=north]      (B3) at (A3.south)      {\includegraphics[width=1in]{images/restaurant}};

%% Captions

\node[anchor=south] (C1) at (A1.north) {\bfseries Ground Truth};
\node[anchor=south] (C2) at (A2.north) {\bfseries Baseline};
\node[anchor=south] (C3) at (A3.north) {\bfseries Proposed};

\end{tikzpicture}
\caption{Comparisons of our proposed architecture}
\end{figure}

\end{document}


If you're not familiar with TikZ, it's worth acquainting yourself with it. You can do some very cool things with it. However, there can be a steep learning curve. Details of the syntax will be explained below.

As I mentioned above, you can use a tabular environment:

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\begin{figure}
\setlength\tabcolsep{2pt}%%
\centering
\begin{tabular}{ccc}
\textbf{Ground Truth} &
\textbf{Baseline} &
\textbf{Proposed} \\
\includegraphics[width=1in]{images/oak_tree} &
\includegraphics[width=1in]{images/oak_tree} &
\includegraphics[width=1in]{images/oak_tree} \\
\includegraphics[width=1in]{images/restaurant} &
\includegraphics[width=1in]{images/restaurant} &
\includegraphics[width=1in]{images/restaurant}
\end{tabular}
\caption{Comparisons of our proposed architecture}
\end{figure}

\end{document}


And this will essentially create an image much like the image posted above.

Discussion

The advantage of the tabular approach is that it's very straight-forward. If you're unfamiliar with the array package, I recommend checking it out. It adds additional features to tabular and array environments and makes them easier to modify to your liking.

The advantage of the TikZ approach is that you have a lot finer control over the presentation of the figure. I would not recommend TikZ as a substitute for tabular, but depending on what you intend to do with such a format, you might like TikZ.

Though to the uninitiated the TikZ syntax may look complex, it's actually fairly simple. I use the node syntax which has the following components:

\node[<options>] (<node name>) at (<location>) {<content>};


Where (<node name>) and at (<location>) are optional.

Nodes can be placed relative to each other, which is what I've done.

The picture format/.style={....} is a way of passing formatting options that will be reused for each node. All this style is accomplishing here is determining the amount of white space around each image: inner sep=2pt.

The anchors are the real beauty here for placing nodes relative to each other. For each node created, there are a variety of useful child nodes created--each named according to the parent node name. For a parent node named A1, the child nodes will be A1.south, A1.south east, A1.east, A1.north east, etc. There are quite a few other child nodes that are created, not just those named according to cardinal directions: for example, A1.baseline and a few others. These child nodes facilitate anchoring each node relative to one another.

I strongly recommend reading the TikZ manual on nodes. The introductory material isn't too hard to assimilate.

• Oh thank you, I do know tabular so I think I would stick with it for a while. – abdul qayyum Sep 27 '18 at 15:10

with use of subfigures from package subcaption the code is short and simple:

\documentclass{article}
\usepackage{graphicx}
\usepackage[skip=1ex,labelfont=bf, textfont=it]{caption}
\usepackage[textfont=rm]{subcaption}

\begin{document}
\begin{figure}[!ht]
\centering
\setkeys{Gin}{width=\linewidth}
\begin{subfigure}{0.3\textwidth}
\caption*{Ground truth}
\includegraphics{example-image-a}\\[3pt]
\includegraphics{example-image-b}
\end{subfigure}
\hfil
\begin{subfigure}{0.3\linewidth}
\caption*{Baseline}
\includegraphics{example-image-a}\\[3pt]
\includegraphics{example-image-b}
\end{subfigure}
\hfil
\begin{subfigure}{0.3\linewidth}
\caption*{Proposed}
\includegraphics{example-image-a}\\[3pt]
\includegraphics{example-image-b}
\end{subfigure}
\caption{Comparison of our proposed architecture with \dots}
\label{fig:comparison}
\end{figure}
\end{document}

• The OP wants the captions on top. Can you do that with subfigure? I don't know. I would love to see how. – A.Ellett Sep 27 '18 at 15:15
• @A.Ellett, thanks for comment. i overlooked this. now is corrected. – Zarko Sep 27 '18 at 15:19