How to make a grid of images?

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
    \advance\@tempdima by \ht0
    \advance\@tempdima by -#1\relax
    \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}

Result

(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.


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:result

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.


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

enter image description here

\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.