Graphics, Figures & TablesFixing figure position with respect to code position

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
betbetbet
Posts: 14
Joined: Thu Jan 22, 2009 10:15 am

Fixing figure position with respect to code position

Post by betbetbet »

Hi, consider the following:

***************code begins

Hello

\begin{figure}

\centering

\resizebox{3in}{!}{\includegraphics{Bgraph3.png}}

\end{figure}

Goodbye

**************code ends

In some situations a figure will be postponed due to the fact that it can't fill the end of the page.

What can I do to the code so that image Bgraph3.png will ALWAYS be after the text "Hello" and ALWAYS before the text "goodbye"?

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Fixing figure position with respect to code position

Post by localghost »

You can start with some suitable placement parameters for the figure environment.

Code: Select all

\begin{figure}[!ht]
  \centering
  \includegraphics[width=3in]{Bgraph3}
\end{figure}
This will pace the figure in most case where declared in the source. Floats are only appear when there is enough space on the page.

Another possible solution is to omit the figure environment. You don't hacto stick to this environment when including an external graphics file. If you need a caption you can use the \captionof command provided by the caption package.

Code: Select all

\begin{minipage}{\linewidth}
  \centering
  \includegraphics[width=3in]{Bgraph3}
  \captionof{figure}{A sample caption}\label{fig:bgraph3}
\end{minipage}
Some other solutions are provided by the float package. Refer to its manual to learn more.

Remark:
When posting code, please use the code environment by clicking the according button right above the input window.

Best regards
Thorsten¹
Post Reply