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
Graphics, Figures & Tables ⇒ positioning/centring problem
NEW: TikZ book now 40% off at Amazon.com for a short time.

positioning/centring problem
1. Use \centering command instead of center environment (i.e. \begin{center}...\end{center}):
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]:
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.
Code: Select all
\begin{figure}
\centering
\includegraphics[width=100mm]{code-1.png}
\caption{Periodic recurrence relation search code}\label{B}
\end{figure}
Code: Select all
\begin{figure}[!h]
\centering
\includegraphics[width=100mm]{code-1.png}
\caption{Periodic recurrence relation search code}\label{B}
\end{figure}

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.
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
positioning/centring problem
Hi Max,
welcome to the board!
Stefan
welcome to the board!
don't use figure inside a center environment, the figure environment should be outside. Even better: use \centering inside figure.hikorski wrote:1. the picture is not centred
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.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.)
Stefan
LaTeX.org admin
Re: positioning/centring problem
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
All the best,
Max