Graphics, Figures & Tablesplacement graphics

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
rockybalboa
Posts: 15
Joined: Wed Mar 04, 2009 12:33 am

placement graphics

Post by rockybalboa »

Hi, I am using the following code to insert a figure. I want it here or on top, but LaTex places it below for some reason. Any help appreciated.

Javier

\begin{figure}[!ht]
\caption{fig}\label{Fig: ergodic}
\centering
\includegraphics[width=6in,height=5in]{myfig}\\
\end{figure}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

placement graphics

Post by localghost »

This code snippet alone is insufficient. Build a minimal working example (MWE) that shows the behaviour you described.

Omit the \\ command for a line break. It is completely superfluous.


Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

placement graphics

Post by Stefan Kottwitz »

Hi Javier,
rockybalboa wrote:I want it here or on top, but LaTex places it below for some reason.
if you want to avoid floating have a look at the possibilities listed here: Prevent floating of figures or tables. Or try the package placeins and its command \FloatBarrier.

Stefan
LaTeX.org admin
fatra2
Posts: 126
Joined: Fri May 01, 2009 1:43 pm

Re: placement graphics

Post by fatra2 »

Hi there,

Your problem might come from the fact that you are misplacing the commands. Firstly, in a figure environment, LaTeX expects the caption and the label after the figure itself. Secondly, like said by localghost, you don't need to tell LaTeX that you want a linebreak after a figure, it is automatic. Thirdly, I believe you are confusing your compiler with the command \begin{figure}[!ht]. It tells your compiler that you want to "force" (!) your figure to be here (h) or on top (t). Try to image if I would force you to be on two different place at once, you would choose the one you like. So keep this information simple, with \begin{figure}[!t]. I don't remember if you are not suppose to add the exclamation after the location [t!]. At last, by define the width and the height of your figure, you will most probably change its original ratio. Why don't you specify one dimension, to keep the ratio of the figure intact.

Hope this helps. Cheers
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

placement graphics

Post by localghost »

fatra2 wrote:[...] Your problem might come from the fact that you are misplacing the commands. Firstly, in a figure environment, LaTeX expects the caption and the label after the figure itself. [...]
The sequence of commands is completely irrelevant to the placement of the float. But in fact, the caption of a figure belongs underneath.
fatra2 wrote:[...] Thirdly, I believe you are confusing your compiler with the command \begin{figure}[!ht]. It tells your compiler that you want to "force" (!) your figure to be here (h) or on top (t). Try to image if I would force you to be on two different place at once, you would choose the one you like. So keep this information simple, with \begin{figure}[!t]. I don't remember if you are not suppose to add the exclamation after the location [t!]. [...]
There will be no confusion for the compiler. The exclamation mark doesn't force the output of a float, but makes the compiler neglect the default settings for placing floats on a page (by reducing the according values). One single parameter will be overwritten with an according warning in the log file. The given combination yields very good results.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
rockybalboa
Posts: 15
Joined: Wed Mar 04, 2009 12:33 am

Re: placement graphics

Post by rockybalboa »

Thanks a lot for all suggestions. I found the command \FloatBarrier and \usepackage{placeins} particularly hepful.

Javier
Post Reply