How to force two figures to stay on the same page in LaTeX?

164,887

Solution 1

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.

Solution 2

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].

Solution 3

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

Solution 4

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.

Solution 5

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

Share:
164,887
Kusti
Author by

Kusti

I'm a web developer/designer from Finland. I am a Co-Founder & cEO of Sharetribe, the easiest way to create an online marketplace for your community. You can follow me on Twitter at http://twitter.com/kusti

Updated on February 06, 2021

Comments

  • Kusti
    Kusti over 3 years

    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
    Kusti over 14 years
    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.
  • bastijn
    bastijn over 14 years
    That is a nice answer to remember :). Never thought of it but it looks clean :).
  • Rupert Nash
    Rupert Nash over 14 years
    Another possibility is the subfigure package and a command inside the figure environment of something like \subfloat[Caption]{\includegraphics{file}}.
  • Crowley
    Crowley over 14 years
    You can also use construction mentioned by Jerred Russel here: stackoverflow.com/questions/1673942/latex-table-positioning Point is in using float package.
  • Boris van Schooten
    Boris van Schooten almost 13 years
    doesn't work, latex will replace it with [ht], then proceed to put the figure on a separate page anyway.
  • Mulone
    Mulone over 12 years
    it seems that you can't \label the two different figures independently, though
  • ely
    ely about 12 years
    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.
  • Kusti
    Kusti almost 12 years
    Changed the "correct answer" flag because this one seems to be the best.
  • fotNelton
    fotNelton over 10 years
    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.
  • Chris
    Chris about 10 years
    @Mulone - It seems you can if you put the \label inside the \caption environment.
  • malteseKnight
    malteseKnight about 9 years
    my labels work fine, outside the caption, but within \begin{center} \end{center}
  • antoine
    antoine over 8 years
    Note: if you want to add some space between Caption1 and fig2, use \vspace{1cm}
  • Danilo Roascio
    Danilo Roascio about 8 years
    @Antoine - To add some space between Caption1 and Figure2 it would be better to use \vspace{\floatsep}
  • Velda
    Velda about 7 years
    Link for second picture in figure will go everytime to top of the figure, not good.
  • HanniBaL90
    HanniBaL90 almost 6 years
    What an elegant solution, never thought it was possible, many thanks ;)
  • Jim C
    Jim C almost 6 years
    Man, you saved my life. Thanks a ton! :-)
  • Anik Islam Abhi
    Anik Islam Abhi about 5 years
    Works in Wiley journal template.
  • Erdem KAYA
    Erdem KAYA over 4 years
    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}