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 a question: can I put 3 pictures one beside the other in the same line? Actually I put them one after the other and I would like to put them in the same line if is possible. This is my code

\begin{figure}[!h]
\centering
   \includegraphics[width=0.4\linewidth,clip,trim=0cm 0cm 8cm 0cm]
   {t1}
  \bf{\caption{Nb des pages qui ont reçu la pub partagé dans le réseau Num 5}}
\end{figure}

 \begin{figure}[!h]
\centering
   \includegraphics[width=0.4\linewidth,clip,trim=0cm 0cm 8cm 0cm]
   {t2}
  \bf{\caption{Nb des pages qui ont reçu la pub partagé dans le réseau Num 7}}
\end{figure}
\newpage
 \begin{figure}[!h]
\centering
   \includegraphics[width=0.4\linewidth,clip,trim=0cm 0cm 8cm 0cm]
   {t3}
  \bf{\caption{Nb des pages qui ont reçu la pub partagé dans le réseau Num 9}}
\end{figure}
share|improve this question
    
It would be great if you could format your code samples by highlighting the code and pressing the {} button. –  Jake May 2 '12 at 21:29
1  
You're trying to fit three images, each with a width of 0.4\linewidth, on a single line (which has a width of 1\linewidth). Do you want them to extend into the margins? –  Jake May 2 '12 at 21:31
    
No I would not extend them into the margins but If it is possible I will change that –  boutheina May 2 '12 at 21:35
1  
\bf{\caption{..}} is not the correct way to make the caption bold. \bf doesn't accept and argument and is outdated for once, but {\bfseries\caption{..}} isn't really correct either. Have a look at the caption package which should allow you to change the font for the captions. –  Martin Scharrer May 2 '12 at 21:43

3 Answers 3

up vote 4 down vote accepted

If you don't want to insert subfigures you can follow Tobi's advice and do like the following (adapted from: http://theoval.cmp.uea.ac.uk/~nlct/latex/novices/sidebyside.html):

\begin{figure}[htbp]
  \begin{minipage}[width=0.33\linewidth]{0.33\linewidth}
    \centering
    \includegraphics{circle}
    \caption{A Circle}
    \label{fig:circle}
  \end{minipage}%
  \begin{minipage}{0.33\linewidth}
    \centering
    \includegraphics[width=0.33\linewidth]{rectangle}
    \caption{A Rectangle}
    \label{fig:rectangle}
  \end{minipage}%
  \begin{minipage}{0.33\linewidth}
    \centering
    \includegraphics[width=0.33\linewidth]{tringle}
    \caption{A Triangle}
    \label{fig:triangle}
  \end{minipage}
\end{figure}
share|improve this answer
    
This may require some adaptation to centre the contents of the figure environment. Like adding \centering outside the minipages. Otherwise you'll have a .01\linewidth gap on the RHS. Additionally, what will happen if the image is greater than 0.33\linewidth? –  Werner May 2 '12 at 22:13
    
Thank you very much for all this answers but when I try some solutions that you suggested I think it is better to leave the 3 figures one after the other because when I put them one beside the other it isn't very clear. –  boutheina May 2 '12 at 22:17
    
@Werner, you're right. I changed with width of each of the image examples to 0.33\linewidth. I thought the 0.1 was negligible, but one can change to 0.3333… or center them all outside the minipage. And of course only use 3 images like that if you want them to be much smaller. –  Joseph May 2 '12 at 22:23
3  
@Joseph: Actually, the image widths should be \linewidth, not 0.33\linewidth, since \linewidth adapts to the width of the line inside the current environment. In this case its set by minipage to be 0.33\linewidth (equivalent to 0.33\textwidth at that point), implying that 0.33\linewidth image is actually 0.1089\linewidth wide... Try it, using \rule{0.33\linewidth}{50pt} for your images/\includegraphics instead. Unless, of course, that's what you meant in the first place. –  Werner May 2 '12 at 22:28
1  
@boutheina: You should upvote all questions you find helpful (by clicking the upward-pointing triangle next to each answer), and accept the one that you found most helpful. This is true for all of your questions, by the way (you haven't upvoted or accepted any answers yet). –  Jake May 2 '12 at 22:31

You can achieve this in several ways. One way is to use the subfig package. Then you can add as many images as you want and LaTeX will try to arrange them on the same line. Here's a small example, edited as suggested.

\documentclass{article}

\usepackage{subfig}
\usepackage[demo]{graphics}

\begin{document}
\begin{figure}[h!t]
        \centering
        \subfloat[3-nearest neighbors]{
            \includegraphics{someimg}
        }
        \subfloat[5-nearest neighbors]{
            \includegraphics{someimg}
        }
        \subfloat[7-nearest neighbors]{
            \includegraphics{someimg}
        }
        \end{figure}


\end{document}

Which gives as result:

enter image description here

share|improve this answer
    
To build an example with inamges without needing to have real images you can use the graphicx package with the option demo and \includegraphics[width=xx,height=yy]{someimg}will print a black rectangle. That’s preferred against building the images with Tikz which blows up the code unnecessarily. Otherwise you can just use \rule{width}{height} to print a black rectangle. –  Tobi May 2 '12 at 21:47
    
Thanks for the hint @Tobi, sorry for not respecting the etiquette. –  Edo May 2 '12 at 21:52
1  
In my eyes there’s no problem with you etiquette ;-) I just wanted to show an alternative way that’s better for minimal examples, in my opinion. In your example you may use real values for xx and yy or leave them out, so graphics uses the default (demo) values … –  Tobi May 2 '12 at 21:58
1  
Just a comment on the placement option, you've used [!ht] which is better (but equivalent) to the [!h] in the question but unless there is strong reason not to, including p as well is always a good idea. Disallowing p (and b) floats just increases the chance that no acceptable position for the floats will be available so they will all go to end of document. –  David Carlisle May 2 '12 at 22:03

TeX doesn’t mind how many figures you ut inside a {figure} environment so you can just put three images in one. Add {minipages} to align them.

fig-align

\documentclass{article}

\usepackage[demo]{graphicx}

\begin{document}
\begin{figure}
   \begin{minipage}[b]{0.3\textwidth}
      \includegraphics[width=\textwidth,height=3cm]{img1}
      \caption{My first image.}
   \end{minipage}
   \hfill
   \begin{minipage}[b]{0.3\textwidth}
      \includegraphics[width=\textwidth,height=4cm]{img2}
      \caption{My second image.}
   \end{minipage}
   \hfill
   \begin{minipage}[b]{0.3\textwidth}
      \includegraphics[width=\textwidth,height=3.7cm]{img3}
      \caption{My third image.}
   \end{minipage}
\end{figure}
\end{document}

Notes

  • Insid of a {minipage} the \texwidth equals the width of the {minipage} an not the main text

  • With the optional argument of {minipage} you can align them vertically. Possible values are c, t or b

  • The \hfill fills the rest of the line (i.e. 0.1\textwidth) with white space.

  • Certainly it’s not requiered to set the height of the images explicitly. I did it just to demonstrate the {minipage} alignment.

Another way is to use sub figures as Edo shows in his answer.

share|improve this answer
    
No one cares, especially TeX...! :) –  Werner May 2 '12 at 22:11
    
@Werner: Thats what I meant :-) [Is this ambiguous in my answer? I’m no native speaker so pleas correct it :-)] –  Tobi May 2 '12 at 22:31

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.