97

I have two images that I want to display on a page as figures. Each eats up little less than half of the space available so there's not much room for any other stuff on that page, but I know there is enough space for both of the figures. I tried to place the figures with [ht] and [hb], both [h] and both [ht] but still I can't get those two images on the same page but instead at least few paragraphs between them.

How do I force those two figures to stay on the same page?

Kusti
  • 1,279
  • 1
  • 10
  • 18
  • A similar question was asked more recently on TeX.SX, and I believe the [answer](http://tex.stackexchange.com/a/65617/7142) using the `\afterpage` command is the best answer. – I Like to Code Feb 23 '14 at 22:45

8 Answers8

172

You can put two figures inside one figure environment. For example:

\begin{figure}[p]
\centering
\includegraphics{fig1}
\caption{Caption 1}
\includegraphics{fig2}
\caption{Caption 2}
\end{figure}

Each caption will generate a separate figure number.

Rob Hyndman
  • 30,301
  • 7
  • 73
  • 85
  • 5
    Another possibility is the subfigure package and a command inside the figure environment of something like `\subfloat[Caption]{\includegraphics{file}}`. – Rupert Nash Nov 24 '09 at 18:38
  • 13
    it seems that you can't \label the two different figures independently, though – Mulone Mar 16 '12 at 16:30
  • 3
    @Mulone - It seems you can if you put the `\label` inside the `\caption` environment. – Chris May 03 '14 at 20:15
  • my labels work fine, outside the caption, but within \begin{center} \end{center} – malteseKnight Apr 13 '15 at 16:33
  • Note: if you want to add some space between Caption1 and fig2, use `\vspace{1cm}` – antoine Oct 05 '15 at 22:49
  • @Antoine - To add some space between Caption1 and Figure2 it would be better to use `\vspace{\floatsep}` – Danilo Roascio May 09 '16 at 20:17
  • Link for second picture in figure will go everytime to top of the figure, not good. – Velda May 10 '17 at 23:59
  • I am not sure whether this is surprising but, the same approach works for tables, too. `\begin{table} \begin{tabular} ... \end{tabular} \begin{tabular} ... \end{tabular} \end{table}` – precise Nov 24 '19 at 20:44
23

If you want to have images about same topic, you ca use subfigure package and construction:

\begin{figure}
 \subfigure[first image]{\includegraphics{image}\label{first}}
 \subfigure[second image]{\includegraphics{image}\label{second}}
 \caption{main caption}\label{main_label}
\end{figure}

If you want to have, for example two, different images next to each other you can use:

\begin{figure}
 \begin{minipage}{.5\textwidth}
  \includegraphics{image}
  \caption{first}
 \end{minipage}
 \begin{minipage}{.5\textwidth}
  \includegraphics{image}
  \caption{second}
 \end{minipage}
\end{figure}

For images in columns you will have [1] [2] [3] [4] in the source, but it will look like

[1] [3]

[2] [4].

Crowley
  • 2,279
  • 6
  • 22
  • 36
  • 1
    You can also use construction mentioned by Jerred Russel here: http://stackoverflow.com/questions/1673942/latex-table-positioning Point is in using `float` package. – Crowley Nov 25 '09 at 18:40
20

I had this problem while trying to mix figures and text. What worked for me was the 'H' option without the '!' option. \begin{figure}[H]
'H' tries to forces the figure to be exactly where you put it in the code. This requires you include \usepackage{float}

The options are explained here

Community
  • 1
  • 1
Schroeder
  • 742
  • 8
  • 19
  • 3
    Yes, the `float` package is definitely the correct answer here. I often lament that using the ! symbol, as in `\begin{figure}[h!]` might as well be rewritten in TeX as `\please` because the compiler still just decides for itself where to put your image. It just winks at you this time instead of ignoring you. The `float` package will make it do what you want for sure. – ely Apr 11 '12 at 22:33
7

If you want them both on the same page and they'll both take up basically the whole page, then the best idea is to tell LaTeX to put them both on a page of their own!

\begin{figure}[p]

It would probably be against sound typographic principles (e.g., ugly) to have two figures on a page with only a few lines of text above or below them.


By the way, the reason that [!h] works is because it's telling LaTeX to override its usual restrictions on how much space should be devoted to floats on a page with text. As implied above, there's a reason the restrictions are there. Which isn't to say they can be loosened somewhat; see the FAQ on doing that.

Will Robertson
  • 62,540
  • 32
  • 99
  • 117
  • 1
    More precisely, `[p]` only tells the compiler to put them on a page with floats only. That might or might not result in separate pages for the two figures, depending on their size. – fotNelton Nov 21 '13 at 09:09
3

Try adding a !, e.g. [h!].

Bastien Léonard
  • 60,478
  • 20
  • 78
  • 95
0

try [h!] first but else you can do it the ugly way.

LateX is a bit hard in placing images with such constraints as it manages placing itself. What I usually do if I want a figure right in that spot is do something like|:

text in front of image here

 \newpage 
 \figure1 
 \figure2

text after images here

I know it may not be the correct way to do it but it works like a charm :).

//edit

You can do the same if you want a little text at top of the page but then just use /clearpage. Of course you can also scale them a bit smaller so it does not happen anymore. Maybe the non-seen whitespace is a bit larger than you suspect, I always try to scale down my image until they do appear on the same page, just to know for sure there is not like 1% overlap only making all of this not needed.

bastijn
  • 5,841
  • 5
  • 27
  • 43
  • Thanks, [h!] worked! I favored your answer because the "ugly way" seems also a good stuff to know even when I didn't need it in this case. – Kusti Nov 24 '09 at 08:41
0

Sometimes we want to put only one caption for two or three related images, and then again, we have two or three associated charts with one caption (for some journals, this style is necessary. In this case, subfloat or other similar environments does not help since they only allow one caption per subfloat, not a cation for all subfloats like the following:

|------|   |------|   |------|
|image1|   |image2|   |image3|
|______|   |______|   |______|
Figure 1. cation for all of the 
subfloats 

|------|   |------|   |------|     
|image1|   |image2|   |image3|   
|______|   |______|   |______|   
Figure 2. cation for all of the 
subfloats 

content of the article,    content of the article
content of the article    content of the article

To produce such a style, I used the following snippet:

\begin{figure}[t]
  \subfloat[]{}
  \subfloat[]{}
  \subfloat[]{}
\end{figure}
\begin{figure}[t!]
  \subfloat[]{}
  \subfloat[]{}
  \subfloat[]{}
\end{figure}
\begin{figure}[t!]
  \subfloat[]{}
  \subfloat[]{}
  \subfloat[]{}
\end{figure}
HamedKhan
  • 61
  • 1
  • 1
  • 6
-2

Try using the float package and then the [H] option for your figure.

\usepackage{float}

...

\begin{figure}[H]
\centering
\includegraphics{fig1}
\caption{Write some caption here}\label{fig1}
\end{figure}

as already suggested by this insightful answer!

https://tex.stackexchange.com/questions/8625/force-figure-placement-in-text

andreagalle
  • 620
  • 6
  • 17