\documentclass{article}
\usepackage{fullpage}
\usepackage{parskip}
\usepackage{hyperref}
\usepackage{graphicx}
\title{Understanding floats}
\author{VK}
\begin{document}
\maketitle
Inserting pictures in to a \LaTeX\ document is easy. Here's a picture of a Duck (taken from \url{http://en.wikipedia.org/wiki/Duck}) \includegraphics{duck.jpg}.
We can place pictures in the middle of a page using the centre environment and set the size of the picture using the width option. Here's a picture of a Chick (taken from \url{http://en.wikipedia.org/wiki/File:Day_old_chick_black_background.jpg}):
\begin{center}
\includegraphics[width=5cm]{chick.jpg}
\end{center}
If we want to make a \textbf{figure} and reference our picture we need to use the figure environment. Figure \ref{rabbit} shows a picture of a Rabbit (taken from \url{http://en.wikipedia.org/wiki/Rabbit}).
\begin{figure}
\begin{center}
\includegraphics[width=5cm]{rabbit.jpg}
\end{center}
\caption{A rabbit}\label{rabbit}
\end{figure}
Note that these figures are called \textbf{floats}. There are two default classes of \LaTeX\ objects that float:
\begin{enumerate}
\item figure
\item table
\end{enumerate}
Floats are able to `float' around a LaTeX document to ensure that spacing is well used. \textbf{Importantly}, this will never change the ordering of floats within a class.
As an example of this we can see that Figure \ref{rabbit} is in fact quite far away from the point at which the code was trying to locate it.
An excellent stackoverflow response explaining how all this works and how to (almost) control it can be found \href{http://tex.stackexchange.com/questions/39017/how-to-influence-the-position-of-float-environments-like-figure-and-table-in-lat}{here}.
In short there are two points worth understanding:
\begin{enumerate}
\item There are various default rules as to where floats can go;
\item There are some options that can be passed to a document to allow the compiler to break those rules.
\end{enumerate}
Figure \ref{mouse} shows an image of a mouse (taken from \url{http://en.wikipedia.org/wiki/Mouse}).
\begin{figure}[t]
\begin{center}
\includegraphics[width=5cm]{mouse.jpg}
\end{center}
\caption{A mouse with the `t' option allowing it to be at the top of the page}\label{mouse}
\end{figure}
The following options can be used:
\begin{itemize}
\item h: try to place the float where the code was asking for it to be place;
\item t: try to place the float at the next top area;
\item b: try to place the float at the next bottom area;
\item p: allow the float to occupy a page by itself (otherwise floats are pushed to the end of the document).
\end{itemize}
A final option that can also be used is:
\begin{itemize}
\item !: place the float while ignoring restrictions linked to number of floats and size of floats.
\end{itemize}
Importantly these constraints can be combined. For example the puppy of Figure \ref{puppy} is placed using the !htbp option.
\begin{figure}[!htbp]
\begin{center}
\includegraphics[width=5cm]{puppy.jpg}
\end{center}
\caption{A puppy with the !htbp option}\label{puppy}
\end{figure}
The order in which the options are called is \textbf{not important} however they are checked by the compiler in the following way:
\begin{enumerate}
\item First check if ! is present;
\item Then check if h is present: if possible will place float \textit{here};
\item Then check if t is present: if possible will place float at next possible \textit{top} area;
\item Then check if b is present: if possible will place float at next possible \textit{bottom} area;
\item Then check if p is present: if possible will place float at next possible \textit{page};
\end{enumerate}
Try to play around with the code in this file and change the options for the rabbit and mouse...
All of this holds for the table environment as well.
\textbf{For a more detailed and comprehensive explenation please take a look at \href{http://tex.stackexchange.com/questions/39017/how-to-influence-the-position-of-float-environments-like-figure-and-table-in-lat}{this stackoverflow question.}}
Finally there are other ways of handling floats:
\begin{enumerate}
\item Using the caption package \url{http://ctan.org/pkg/caption} to caption a graphical object outside of a figure environment. Similarly there is also the capt-of package: \url{http://www.ctan.org/pkg/capt-of}.
\item Using the H option with the float package \url{http://www.ctan.org/pkg/float}.
\item Modifying the default float restriction: \url{http://mintaka.sdsu.edu/GF/bibliog/latex/floats.html}.
\end{enumerate}
\end{document}