%Old stuff
\documentclass[12pt,a4paper]{amsart}
\usepackage{amsmath,amsthm,amssymb}

%Generates text so we can test spacing
\usepackage{lipsum}

%Margins - ``Easy''
\usepackage[a4paper,left=1in,right=1in,top=1in,bottom=1in,footskip=.25in]{geometry}

%smiley faces
\usepackage{wasysym}

%Figures
\usepackage{graphicx}
\usepackage{subfig}

\usepackage{hyperref}

%Document Header
\title[Figures and Floats]{A Short Guide to Floats and Figures in \LaTeX}

\author[Kresge \LaTeX Workshop]{Daryl DeFord\and David Freund \and Katie Harding}
%\address{Dartmouth College\\Hanover NH 03755}




\begin{document}
\maketitle
\tableofcontents

This is an example document exploring some of the properties of floats and figures in \LaTeX. The .tex file is included on the \href{http://www.math.dartmouth.edu/~ddeford/latex.php}{webpage} so that you can use the examples as templates as you start creating your own documents. 

\section{Floating Environments}

\LaTeX\ recognizes automatically two kinds of floating environments: tables and figures. Although it is not necessary to put tables or figures in a floating environment it is usually beneficial to do so. Most importantly, putting an object in a floating environment tells \LaTeX not to try to split it across pages and allows the software to try to place it in an appropriate position in the document. Additionally, by creating a floating environment for our object, \LaTeX\ will allow us to automatically number, caption, and label our object and update these labels as we continue to work. 

To start a floating environment we use the familiar \verb|\begin{}...\end{}| syntax. Both of the floating environments takes an optional argument allowing you to ``suggest'' a placement for the float. The \LaTeX\ processor considers the options in the following order, regardless of the order that you place them in the brackets\footnote{so [tb] and [bt] will always produce the same output.} \begin{enumerate}
\item {\bf h} for ``inline''
\item {\bf t} for top of page
\item {\bf b} for bottom of page
\item {\bf p} for new page
 figures
\end{enumerate}

Adding an exclamation mark before the symbol (\verb|[!h]|) tells \LaTeX\ to ignore some of the standard restrictions on float placement. Even with this in mind floats can end  up in surprising places due to size restrictions and the amount of free space available. The float package introduces a new placement argument (\verb|[H]|) that forces floats to remain in place. However, this is usually a mistake -- \LaTeX\ almost always has a good reason for placing floats where it does. 

Within a floating environment we can add captions and labels. The syntax for captioning is simple: \verb|\caption{Description of figure goes here.}|. This will produce:
\begin{center} \verb| Figure #. Description of figure goes here.|\end{center} where \# is the number of the figure in the document. \LaTeX\ will place the caption either above or below the floating object depending on where the \verb|\caption{}| is placed in the floating environment. The floating environments also support the \verb|\label{*} \ref{*}| commands for automatic labeling and referencing.


\subsection{Example Table}
We learned how to construct a generic table last week. Now we can put that table in a floating environment:
\begin{table}[!h]
\caption{A great looking table \smiley.}

\begin{tabular}{|l|c|c|c|c|c|}
\hline
$\otimes$&\multicolumn{2}{|c|}{Colors}&\multicolumn{3}{|c|}{Gerunds}\\
\hline
\hline
1&Red&Blue&Studying&Constructing&Applying\\
\hline
2&Orange&Yellow&Building&Finding&Analyzing\\
\hline
3&Green&Pink&Investigating&Creating&Triangulating\\
\hline
\end{tabular}

\label{Tab:1}
\end{table}

Play around with inserting text above and below the table with the lipsum package (\verb|\lipsum[1-4]|) and adjusting the optional position command (currently \verb|[!h]|). How does the table move around the document?
Putting a \verb|\label| in the float means that we can reference the table later using \verb|\ref{Tab:1}|. For example, we could write: the information in Table  \ref{Tab:1}  is critically important. Even better it gets automatically linked for us using the hyperref package and \LaTeX\ will take care of renumbering it for us if we decide to reorder our paper later. 

\section{Figures}
The standard package for including figures in \LaTeX\ is the graphicx package. You can see the we have included it in the preamble with \verb|\usepackage{graphicx}|. The subfig package (\verb|\usepackage{subfig}|) is also very useful for including and labeling several related images in the same figure. 

The basic syntax for adding an image to your document is:\begin{center} \verb|\includegraphics[options]{image_name}|\end{center}
you might have noticed that the example above\footnote{and the examples below} does not include a file extension for the figure. In general, this is a \LaTeX\ best practice -- as the compiler will determine the appropriate filetype if there are multiple figures with the same name -- and as long as you are building to PDF\LaTeX\ you shouldn't have to worry too much. 

There are three main types of optional arguments that go before the filename: sizing, rotating, and cropping. The size of the figure can either be controlled by a multiplicative scaling parameter \verb|scaling=2| or a fixed height or width \verb|height=2in|. Rotations are set by an angle measured in degrees, so \verb|angle=180| will turn your figure upside down. Trimming the figure requires the argument \verb|clips=true| as well as a list of four lengths describing how much to crop off each side
counterclockwise from the left, so \verb|trim=1em 2em 0em 5em| removes 1em off the left, 2em off the bottom, nothing off the right, and 5em off the top. 

Occasionally, you may wish to include multiple figures in the same floating environment. In order to generate separate labels and captions for each image you can use the subfloat package. Inside the figure environment you can create subfigures with:
\begin{center}
\verb|\subfloat[sublabel 1]{\includegraphics[options]{image1_name}}|
\verb|\subfloat[sublabel 2]{\includegraphics[options]{image1_name}}|
\end{center}
You can use the standard horizontal and vertical spacing commands between the subfloats to arrange them within the figure environment. 
\subsection{Example Figures}
Here are some example figures that you can use as templates. You can download the sample images for these figures \href{http://www.math.dartmouth.edu/~ddeford/LaTeX_Figures.zip}{here.}

\begin{figure}[!h]

\includegraphics[scale=.4]{noise}
\caption{Basic Figure Example}
\end{figure}

\begin{figure}[!h]

\includegraphics[height=1.25in,angle=60]{chseal}
\caption{Scaled and Rotated Figure Example}
\end{figure}

\begin{figure}[!h]
\begin{center}
\subfloat[Math Logo]{\includegraphics[height=1in]{mlogo}}\qquad\qquad
\subfloat[Noise]{\includegraphics[height=1in]{frown}}\qquad\qquad
\subfloat[Seal]{\includegraphics[height=1in]{chseal}}
\caption{Subfig Example}
\end{center}
\end{figure}
\begin{figure}
\subfloat[.eps]{\includegraphics[height=.5in]{noise.eps}}\quad\quad
\subfloat[.png]{\includegraphics[height=.5in]{noise.png}}\quad\quad
%\includegraphics[height=.5in]{noise.tif} doesn't work
\subfloat[.jpg]{\includegraphics[height=.5in]{noise.jpg}}\quad\quad
\subfloat[.pdf]{\includegraphics[height=.5in]{noise.pdf}}\quad\quad
%\includegraphics[height=.5in]{frown.bmp}
\subfloat[none]{\includegraphics[height=.5in]{noise}}
\caption{Different File Extension Noise}
\end{figure}

\end{document}