Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

4 Answers 4

up vote 13 down vote accepted

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.

share|improve this answer
2  
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
1  
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
1  
@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
1  
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
show 4 more comments

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.

share|improve this answer
    
I really love the way ConTeXt handles this case –  EEva Jun 13 '12 at 10:18
add comment

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
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.