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

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?

This question is related to image layout latex figure

The answer is


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


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.


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


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


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.


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


Examples related to image

Reading images in python Numpy Resize/Rescale Image Convert np.array of type float64 to type uint8 scaling values Extract a page from a pdf as a jpeg How do I stretch an image to fit the whole background (100% height x 100% width) in Flutter? Angular 4 img src is not found How to make a movie out of images in python Load local images in React.js How to install "ifconfig" command in my ubuntu docker image? How do I display local image in markdown?

Examples related to layout

This view is not constrained What's the difference between align-content and align-items? CSS Flex Box Layout: full-width row and columns Fill remaining vertical space with CSS using display:flex What is setContentView(R.layout.main)? How to change line color in EditText Scrolling a flexbox with overflowing content UICollectionView - Horizontal scroll, horizontal layout? How to style a div to be a responsive square? 100% width Twitter Bootstrap 3 template

Examples related to latex

How to write LaTeX in IPython Notebook? latex tabular width the same as the textwidth Add "Appendix" before "A" in thesis TOC Tools for making latex tables in R Beamer: How to show images as step-by-step images multiple figure in latex with captions Two statements next to curly brace in an equation Latex Remove Spaces Between Items in List How to change font size on part of the page in LaTeX? Inserting code in this LaTeX document with indentation

Examples related to figure

Error in plot.new() : figure margins too large, Scatter plot Python Matplotlib figure title overlaps axes label when using twiny How to save a figure in MATLAB from the command line? Matplotlib different size subplots How to use matplotlib tight layout with Figure? Matplotlib (pyplot) savefig outputs blank image matplotlib savefig in jpeg format How do I tell Matplotlib to create a second (new) plot, then later plot on the old one? In Matplotlib, what does the argument mean in fig.add_subplot(111)? How to force two figures to stay on the same page in LaTeX?