Graphics, Figures & TablesImage appears on next page if I use a caption

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jessie tex
Posts: 2
Joined: Thu Sep 24, 2015 6:07 pm

Image appears on next page if I use a caption

Post by jessie tex »

If I don't include a caption then my image sits under my writing, eg:

Code: Select all

\documentclass[11pt]{article}
\usepackage{graphicx}
\title{Trying}
\author{Ksks}
\begin{document}
\maketitle
Hello.
\begin{figure}[!h]
\centering
\includegraphics[scale=0.75]{plot.jpg}
\end{figure}
\end{document}
But when I include a caption then it jumps to the next page. My image is small and doesn't take up much space (it's not like it's near the bottom of the page in the first one).

Any help would be hugely appreciated.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Image appears on next page if I use a caption

Post by Johannes_B »

Welcome, do you know why you are using the {figure} environment? That floating is on purpose. If you want to decide where a picture goes, you can use the Hammer method provided by package float, but I advise you not to and let LaTeX do all the positioning.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
jessie tex
Posts: 2
Joined: Thu Sep 24, 2015 6:07 pm

Re: Image appears on next page if I use a caption

Post by jessie tex »

I'm not sure, I followed a YouTube tutorial. Do you know what I should use instead?

Actually, done it. Thank you for your help!
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Image appears on next page if I use a caption

Post by cgnieder »

It is hard to believe that the small example you posted compiles to two pages.

However, the caption may very well make the contents of the {figure} environment too big for the remaining space. And then the floating property of the {figure} environment shows its effect.

The {figure} environment (like the {table}) is a floating environment. It is used to allow its contents to be moved to a place where it fits best.

By saying [!h] you only allow the float to be placed here. That is – not quite: h means place here if it fits. As this very often isn't the case LaTeX will very likely change this into ht and then place the float in the top area (t) of the next page. In the small example the bang is completely irrelevant (IIRC it only comes into effect if several floats are to be placed).

Frank Mittelbach has written a detailed explanation on how the floating mechanism works and how it can be influenced.

If you don't want your figure to float then there are easier ways than [!h] (which doesn't prevent floating, anyway)
site moderator & package author
Post Reply