Graphics, Figures & Tablespositioning/centring problem

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
hikorski
Posts: 4
Joined: Sun May 16, 2010 4:58 pm

positioning/centring problem

Post by hikorski »

I have what is probably a simple problem - I have used the code below to import a graphic:

\begin{center}
\begin{figure}
% Requires \usepackage{graphicx}
\includegraphics[width=100mm]{code-1.png}\\
\caption{Periodic recurrence relation search code}\label{B}
\end{figure}
\end{center}

I have put \usepackage{graphicx} at the top of my document. I find:

1. the picture is not centred
2. the picture appears at a different place to that chosen in the source code (in fact, at the top of a page.)

I have looked for help in previous postings, but with no joy. As you can see, I am in the early stages of learning Latex, and any help would be gratefully received,

Best wishes,

Max Hikorski

Recommended reading 2024:

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

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

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

positioning/centring problem

Post by meho_r »

1. Use \centering command instead of center environment (i.e. \begin{center}...\end{center}):

Code: Select all

\begin{figure}
\centering
\includegraphics[width=100mm]{code-1.png}
\caption{Periodic recurrence relation search code}\label{B}
\end{figure}
2. When you use figure environment, LaTeX finds a best spot to place your picture in. It often means that the picture will appear on a place different from the place where the code is. Of course, this behaviour is easily changed, e.g., telling LaTeX to put the picture "here" [!h]:

Code: Select all

\begin{figure}[!h]
\centering
\includegraphics[width=100mm]{code-1.png}
\caption{Periodic recurrence relation search code}\label{B}
\end{figure}
Here's some literature on LaTeX basics you may find useful ;) And here you can find a quick overview of floats in LaTeX.

Welcome to the forum :)

EDIT: Corrected some typos.
Last edited by meho_r on Thu Jul 08, 2010 8:40 pm, edited 4 times in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

positioning/centring problem

Post by Stefan Kottwitz »

Hi Max,

welcome to the board!
hikorski wrote:1. the picture is not centred
don't use figure inside a center environment, the figure environment should be outside. Even better: use \centering inside figure.
hikorski wrote:2. the picture appears at a different place to that chosen in the source code (in fact, at the top of a page.)
That's common, figures should be placed where they fit well, not always at the exact point where they are in the source code, perhaps leading to very bad page breaks. Have a look at epslatex.

Stefan
LaTeX.org admin
hikorski
Posts: 4
Joined: Sun May 16, 2010 4:58 pm

Re: positioning/centring problem

Post by hikorski »

Many thanks, meho_r and stefan_k, you have solved my problem instantly. Thank you also for your welcome to the forum; I will try to work things out for myself, but it is great to know that help is at hand!

All the best,

Max
Post Reply