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 have this LaTeX code which should place this two images on the left and the right of the page:

\begin{flushright} \begin{figure}[H]
\includegraphics[width=107px ,
height=134px]{t1.jpg} \end{figure}
\end{flushright}

\begin{flushleft} \begin{figure}[H]
\includegraphics[width=113px ,
height=190px]{t2.jpg} \end{figure}
\end{flushleft}

but the two images are placed one at the top of the other, why??

share|improve this question
    
flushright and flushleft are not standard latex environments. Are you loading some package or special documentclass that is providing them? –  Lev Bishop Jun 21 '11 at 15:58
3  
@Lev: No, you are wrong. Both of these environments are provided by LaTeX. They are the environment versions of \raggedleft and \raggedright. –  Martin Scharrer Jun 21 '11 at 16:02
    
@Martin. You appear to be right. Not sure why I thought otherwise. –  Lev Bishop Jun 21 '11 at 18:44
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count. This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). –  N.N. Jul 1 '11 at 12:24

4 Answers 4

up vote 5 down vote accepted

There are a number of issues:

figure is a floating environment. It is not placed directly but stored and placed where LaTeX thinks it fits best. This can be influenced by the optional argument like [H] but surrounding alignment environment still don't have any influence on it.

flushleft and flushright produce paragraphs and therefore a line break. So both contents will always vertical stacked, never side by side.

Note that you don't need a figure environment to use \includegraphics, only if you want a caption. Also you can have multiple images and captions (!) in one figure. Try the following code to place the two images side-by-side and at the left and right corner (if this is what you want):

\begin{figure}[H]
\includegraphics[width=107px,height=134px]{t1.jpg}%
\hfill
\includegraphics[width=113px,height=190px]{t2.jpg}%
\end{figure}
share|improve this answer
    
your code place them side by side but on the same level , why? –  smack Jun 21 '11 at 21:50
    
@smack: The images are aligned at their baseline which is at the bottom. If you want to have them also vertical aligned you can put the \includegraphics commands also in a \raisebox{-.5\height}{...} command each. –  Martin Scharrer Jun 22 '11 at 1:33

If the figures are related, you could also create one figure with subfigures.

There is a package available to do this: subfig

For subfig,

\usepackage{subfig}

\begin{figure}
\centering
\subfloat[caption]{\includegraphics[]}
\subfloat[caption]{\includegraphics[]}
...
\end{figure}

There are more details on options in their respective package descriptions. Also mentioned in the comment is subcaption

share|improve this answer
    
subfigure is obsolete and shouldn't be used anymore. As Leo Liu suggested, subfig or, even better, subcaption can be used instead. –  Gonzalo Medina Jun 21 '11 at 19:13
    
thanks... i wasnt sure about that... i'll update the answer –  nbz Jun 22 '11 at 10:01

Some more explanations:

First of all, a figure environment is actually a \vbox of width \columnwidth (with many properties). It is impossible to put two successive figure environments (float or non-float) side by side.

Furthermore, you cannot use flushleft environment and flushright environment to typeset side by side materials. The two environments are defined using trivlist environment. They can only placed vertically, if not included in other boxes.

You should, as Martin does, put the two images into one figure environment. And use subcaption or subfig package if you want separate sub-captions.

share|improve this answer

You don't need any figure environment, if you don't want to add a caption. Just write

\begin{center}
\includegraphics[width=107px,height=134px]{t1.jpg}%
\hfill
\includegraphics[width=113px,height=190px]{t2.jpg}
\end{center}

The two images will be vertically aligned at their bottom.

share|improve this answer
    
Egreg: Would it be optimal to use \begin{center}...\end{center} in this case of two figures with no captions, rather than using \centering? –  night owl Oct 9 '11 at 22:28
    
center will add some vertical space fore and aft; \centering requires braces and a final \par before the closing brace. –  egreg Oct 9 '11 at 22:30

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.