# How to make a grid of images?

Is it possible to place 4 images in an 2x2 grid? I don't want to float them, I don't want any captions. Each image should have the same width.

Edit:

Thanks for all the answers. After trying it out, I realized, that I forgot to ask one point:

Suppose I have a counter like this:

\newcounter{eqn}
\renewcommand*{\theeqn}{\alph{eqn})}
\newcommand{\num}{\refstepcounter{eqn}\text{\theeqn}\;}


Now I want to add \num before each picture, the enumeration should be displayed above to the left of each image.

This works for me:

\documentclass{article}

\usepackage{amsmath}

\newcounter{eqn}
\renewcommand*{\theeqn}{\alph{eqn})}
\newcommand{\num}{\refstepcounter{eqn}\text{\theeqn}\;}

\makeatletter
\newcommand{\putindeepbox}[2][0.7\baselineskip]{{%
\setbox0=\hbox{#2}%
\setbox0=\vbox{\noindent\hsize=\wd0\unhbox0}
\@tempdima=\dp0
\dp0=\@tempdima
\ht0=#1\relax
\box0
}}
\makeatother

\usepackage[demo]{graphicx}

% \setlength{\tabcolsep}{0pt}

\begin{document}

\begin{tabular}{cc}
\num\putindeepbox[7pt]{\includegraphics{whatever.jpg}}
& \num\putindeepbox[7pt]{\includegraphics{whatever.jpg}} \\
\num\putindeepbox[7pt]{\includegraphics{whatever.jpg}}
& \num\putindeepbox[7pt]{\includegraphics{whatever.jpg}} \\
\end{tabular}

\end{document}


(Edited to include pseudo-captions; the macro \putindeepbox takes something and puts it into a box of height equal to 0.7\baselineskip by default (i.e., the height of a \strut) and deep enough to accomodate for the given material. Somehow in tabular \baselineskip gets reset to zero, so I've hardcoded the height manually. Not very elegant, but works - feel free to improve it;). Notice also some dirty tricks with boxes - hopefully someone will find a cleaner way to do it. I hope that this is what you wanted, and that it is not too late... See also comments below to make spacing better.)

The spacing is not perfect; you can manipulate the horizontal spacing with tabcolsep, AFAIK there is no such parameter for vertical spacing in tabular.

• You could use \usepackage[demo]{graphics} to avoid needing a 'real' image at all. – Joseph Wright Dec 7 '11 at 17:26
• Wow, I didn't know about that functionality, thanks! I'll modify my code above. – mbork Dec 7 '11 at 17:31
• You might also want to change {cc} to {@{..}c@{..}c@{..}} where .. is some space command like \hspace{<length>}, in order to control the exact horizontal distance between the images. A \rule[<length>]{0pt}{0pt} can be used to add a negative space inside the top row to push the bottom row down. – Martin Scharrer Dec 7 '11 at 18:21
• @user4011: I'm sorry, somehow I missed your question... I've edited my answer. @hhh: see e.g. the pgffor package. – mbork Jan 16 '12 at 23:44
• You might want to look at the adjustbox package. Or use \raisebox{-\dimexpr\height+\ht\strutbox\relax}{\includegraphics{...}} instead of that complicated computation. With \usepackage[export]{adjustbox} it becomes \includegraphics[valign=t]{...} – egreg Jan 17 '12 at 0:19

Here is a ConTeXt solution:

\useMPlibrary [dum]  % for placeholder pictures
\starttext

\startcombination [2*2]
{\externalfigure[placeholder]}{a}
{\externalfigure[placeholder]}{b}
{\externalfigure[placeholder]}{c}
{\externalfigure[placeholder]}{d}
\stopcombination

\stoptext


The result is:

When captions are not necessary, simply leave the second braces empty. The distance between the images can be set up with the command \setupcombinations, see setupcombinations reference.

• I really love the way ConTeXt handles this case – MP0 Jun 13 '12 at 10:18
• This was exactly what i was looking for. I almost feel guilty that it's so simple. TeX is supposed to make me suffer and make me feel grateful when something comes out how I wanted! – Sridhar-Sarnobat Jan 9 '16 at 5:48

For even distribution on either side of the images, use a combination of \hfills:

\documentclass{article}
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
\begin{document}

Here is some text.\strut

\noindent\null\hfill\includegraphics{one} \hfill
\includegraphics{two} \hfill\null

\noindent\null\hfill\includegraphics{three} \hfill
\includegraphics{four} \hfill\null

Here is some more text.
\end{document}​


\null is to fool LaTeX in thinking there's something there from which to add the horizontal fill. \strut is used to improve the \baselineskip from the top paragraph, since it has no descenders (p, or q, or the like). You can set the image width, of course, using the width=<len> key-value pair of the \includegraphics command.

The demo option to graphicx is merely for display purposes, allowing to typeset an image as a 150pt x 100pt black rectangle regardless of whether the image exists or not.

Well, if you do not have captions, use just \includegraphics:

\noindent
\includegraphics[width=0.4\textwidth]{one}\hspace{0.2\textwidth}%
\includegraphics[width=0.4\textwidth]{two}\\[2em]
\includegraphics[width=0.4\textwidth]{three}\hspace{0.2\textwidth}%
\includegraphics[width=0.4\textwidth]{four}\par