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.

I want to create the following layout:

 ------------                                                                  -------------
|   IMAGE 1  |                                                                |   IMAGE 2   |
|____________|                                                                |_____________|

Notice that the two images are relatively small in size, but I want them to be placed at the right/leftmost edge of the document. I tried it using minipages like this:

\begin{minipage}{4cm}
    \includegraphics[width=4cm]{image1.eps}
\end{minipage}

\begin{minipage}{4cm}
    \begin{flushright}
        \includegraphics[width=4cm]{image2.eps}
    \end{flushright}
\end{minipage}

But then, the two images are placed like this:

 ------------
|   IMAGE 1  |
|____________|

 -------------
|   IMAGE 2   |
|_____________|

I fooled around with the values of minipage and image-width, but nothing seems to help...

Edit: Also, I need the images to be centered to each other (horizontally speaking), so they are nicely aligned if one is bigger than the other.

share|improve this question
2  
What happens if you do \includegraphics[width=4cm]{image1.eps}\hfill\includegraphics[width=4cm]{image2‌​.eps}? –  Andrew Stacey Apr 29 '11 at 12:39
1  
(Incidentally, the flushright does nothing because it is inside the minipage, and your minipage and graphic are the same size. That the two are on separate lines is caused by the blank line between the minipage environments: that starts a new paragraph.) –  Andrew Stacey Apr 29 '11 at 12:40
    
The empty line between the minipages is inserting a new paragraph which make the second image be placed below the first. You need to avoid this. –  Martin Scharrer Apr 29 '11 at 13:02
add comment

2 Answers

up vote 9 down vote accepted

You can use \hfill to add a horizontal filler between both images. This will push the second image to the right. You need to watch empty lines here because they create new paragraphs. You should add a new paragraph before and after both images, but not between them. In the example code I added explicit \pars to highlight this, but implicit ones i.e. empty lines are fine, too.

You can vertical center both images using \raisebox. Images included with \includegraphics only have a height but no (=zero) depth. Every box (character, image, ...) in (La)TeX has a height, width and depth. Everything below the baseline (the invisible line the letters are placed on) is part of the depth. The \raisebox command allows you to raise or lower its content but also to set the official width and height of it which can be larger or smaller than the original, the natural amount. The original height can be accessed by the \height length. Use \raisebox{-.5\height} to lower the images half under the baseline. This will effectively center them vertically.

\documentclass{article}

\usepackage{graphicx}
\usepackage{lipsum}% For example text

\begin{document}

\lipsum[1]

\par
\raisebox{-.5\height}{\includegraphics[width=4cm]{image1}}%
\hfill
\raisebox{-.5\height}{\includegraphics[width=4cm]{image2}}%
\par

\lipsum[2]

\end{document}

Result

You could also put the above code into \makebox[\textwidth]{...} to ensure they are on one line if you don't like the \pars.

share|improve this answer
    
nice. I'd forgotten about \height. –  Ian Thompson Apr 29 '11 at 13:33
    
\makebox didn't do it... but \raisebox worked perfectly. Thanks a bunch –  Florian Peschka Apr 29 '11 at 13:33
    
@ApoY2k: I meant to use \makebox with \raisebox: \makebox[\textwidth]{\raisebox{-.5\height}{\includegraphics[width=4cm]{image1}}‌​\hfill \raisebox{-.5\height}{\includegraphics[width=4cm]{image2}}}%, just to ensure both are on one line. Using paragraph breaks around it achieves the same. –  Martin Scharrer Apr 29 '11 at 13:39
add comment

How about this?

\includegraphics[width=4cm]{image1.eps}
\hspace{\fill}
\includegraphics[width=4cm]{image2.eps}

\hspace{\fill} uses up all available space, pushing your images to the margins.

You can adjust the vertical alignment using minipages, so your original example would become something like this:

\documentclass{minimal}
\begin{document}
\begin{minipage}[c]{4cm}
\framebox{ABC \rule{1pt}{1cm}}
\end{minipage}
\hspace{\fill}
\begin{minipage}[c]{4cm}
\framebox{DEF \rule{1pt}{10cm} }
\end{minipage}
\end{document}

More details on this can be found in epslatex.pdf

share|improve this answer
    
That works nicely, but now there's a second problem; the second image is now aligned to the bottomline of the first - how can I get it to align to the center (horizontally speaking) –  Florian Peschka Apr 29 '11 at 12:52
    
You might write a line about what \hspace and \hfill commands, that will make your answer even better. –  ipavlic Apr 29 '11 at 12:57
1  
I would just write \hfill instead. –  Martin Scharrer Apr 29 '11 at 13:04
    
@ApoY2k: You should update your question with the vertical alignment requirement. –  Martin Scharrer Apr 29 '11 at 13:04
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.