LaTeX forum ⇒ Graphics, Figures & Tablesbegin{figure} always puts the image at the beginning of the relative page

Information and discussion about graphics, figures & tables in LaTeX documents.
ssimo
Posts: 2
Joined: Sat Mar 25, 2017 2:00 pm

begin{figure} always puts the image at the beginning of the relative page

Postby ssimo » Sat Mar 25, 2017 2:15 pm

Hello,

This is my 1st post and I writing because I have a formatting problem when using the

\begin{figure}
% img here
\end{figure}


block. It always put tne image at the beginning of the page, so without respecting the order and the placement of the image, except for the first one.
The syntax I use for each image (and which is giving me these problems) is:

\begin{figure}
\centering
\includegraphics[scale=0.4]{\imagesDir/image.png}
\caption{\footnotesize{ image caption here }}
\label{fig:fign}
\end{figure}


while if I use:

\begin{center}
\includegraphics[scale=0.4]{\imagesDir/image.png}
\center{\footnotesize{ image caption here }}
\end{center}


I don't have these problems, but I cannot reference the image and automatically enumate it as the \begin{figure} block does..

How can I solve my problem ?
Do you have any suggestion for it ?
Thanks,
s.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
ssimo
Posts: 2
Joined: Sat Mar 25, 2017 2:00 pm

begin{figure} always puts the image at the beginning of the relative page

Postby ssimo » Sat Mar 25, 2017 2:39 pm

Solved !

The solution is explained here : https://en.wikibooks.org/wiki/LaTeX/Flo ... ns#Figures
I love that wikibook. :)

Simon

User avatar
Stefan Kottwitz
Site Admin
Posts: 10224
Joined: Mon Mar 10, 2008 9:44 pm

begin{figure} always puts the image at the beginning of the relative page

Postby Stefan Kottwitz » Sat Mar 25, 2017 3:44 pm

Hi Simon,

welcome to the forum!

Thanks for the link. The easiest way for most flexible positioning as near as possible with good page breaks is \begin{figure}[!htbp], so allowing all, no general restrictions. That's what I use most of the times.

Sometimes \begin{figure}[H] for placing exactly here, forced, can be good, and allows referencing, same syntax. It just has a risk that page breaks are not good if you don't allow floating that way.

Stefan
LaTeX.org admin

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

begin{figure} always puts the image at the beginning of the relative page

Postby cgnieder » Sat Mar 25, 2017 5:59 pm

Stefan Kottwitz wrote:Sometimes \begin{figure}[H] for placing exactly here, forced, can be good, and allows referencing, same syntax.

You should mention that
\documentclass{article}
\begin{document}
\begin{figure}[H]
\end{figure}
\end{document}

will give the error
! LaTeX Error: Unknown float option `H'.

and that packages float or here are needed. But then, package float has other disadvantages which is why I nowadays tend to say that
\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{center}
  ...
  \captionof{figure}{...}
\end{center}
\end{document}

is the better solution for non-floating figures.

ssimo wrote:The solution is explained here : https://en.wikibooks.org/wiki/LaTeX/Flo ... ns#Figures


You might also be interested in Frank Mittelbachs extended explanation in TUGboat volume 35, number 3, 2014: How to influence the position of float environments like figure and table in LaTeX?

Regards
site moderator & package author

User avatar
Stefan Kottwitz
Site Admin
Posts: 10224
Joined: Mon Mar 10, 2008 9:44 pm

begin{figure} always puts the image at the beginning of the relative page

Postby Stefan Kottwitz » Sun Mar 26, 2017 12:01 am

Yes, I forgot to mention, that for using the H option, \usepackage{float} is needed.

Nowadays I tend to prefer figure with H over center and \captionof, because the syntax then stays the same, and it can easily be changed to floating or back. Let's say at the very end for printing, one can change H to !hb or !htbp or, the other way round, some floating figures to H if it's a better match within the text and the page break is fine. But the latter is just for final tweaks. Main reason for me is the consistent syntax. And the easy way to change to proper floating. :-)

Stefan
LaTeX.org admin


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 29 guests