# Layout problems with tables and graphics (eps files) - they're all over the place!

I know I'm doing something dumb here but I can't figure it out.

I am creating a .tex file with a header:

%% XXXXXXXXXXXXXX created this file.
\documentclass[english]{article}
\usepackage{avant}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{color}
\usepackage{babel}
\usepackage{array}
\usepackage{float}
\usepackage{graphicx}
\usepackage{parskip}
\usepackage[bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
{hyperref}
\hypersetup{pdftitle={XXXXXX},
pdfauthor={Autogenerated by XXXXXX}}
\providecommand{\tabularnewline}{\\}
\usepackage{color}
\begin{document}


Then a number of sections:

\section{\textsf{Section Name}}


Each containing several tables and graphs:

\begin{tabular}{|l|r|r|r|r|r|}
\hline
& 1 Month & 3 Month & 6 Month & Average & Total\tabularnewline
\hline
World&-12.6867&-14.984&-19.1529&-15.9345&-95.6071\tabularnewline
\hline
Data Title&-12.6867&-14.984&-19.1529&-15.9345&-95.6071\tabularnewline
\hline
\end{tabular}
\newline
\vspace*{.25 cm}
\newline

\begin{figure}[h!]
\centering
\includegraphics[scale=.8]{MyGraph}
\caption{World}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[scale=.8]{World}
\caption{World}
\end{figure}


Each section is far larger than a page, but before each section I have a

\newpage


For simple (ie very few sections / tables / graphs) the rendering to pdf via xelatex is often perfect. However once the document gets larger the tables are always in order but the graphs are all over the place - almost randomly.

I know I'm doing (or not doing) something really dumb here. I just want everything to appear in the order I write it.

Can anyone offer any assistance please?

-
Hi Tom, welcome to TeX.sx. I removed the thanks which is just the style here. I also removed the sign off, which is not necessary as your user icon is placed with the question. –  qubyte Dec 22 '11 at 15:51
–  Torbjørn T. Dec 22 '11 at 15:52

figures are floating environments, tabulars are not. So the tabulars go exactly where they are in the source, but LaTeX puts the figure where it thinks makes the document "look" the best.

My understanding is that even with the [h] or [h!] options to the figure environment the figure cannot always be placed "right here." LaTeX will disobey you.

A workaround (via Mark Mengel) would be to avoid the figure environment:

\newcommand{\figcaption}[1]{
{\center Figure \arabic{figure} #1\\ }
}


Then instead of a figure environment you can do:

\begin{center}
\includegraphics[scale=.8]{MyGraph}
\figcaption{World}
\end{center}


Another workaround would be to hack the float-placement algorithms. But I don't know how to do that.

-
The caption package provides \captionof{figure}{This is the caption.}. To avoid a pagebreak between figure and caption, perhaps a minipage instead of center? Lastly, the float package provides the H float specifier, which basically disables floating. –  Torbjørn T. Dec 22 '11 at 16:10
Ha, perfect, cheers! –  Tom Dec 22 '11 at 16:18
@Tom: An upvote beats a cheers! –  qubyte Dec 22 '11 at 16:32
@TorbjørnT. Agreed, the float package does the necessary hacking. I learned about it after I posted, but got the upvotes and accept before I could delete my inferior answer. –  Matthew Leingang Dec 22 '11 at 18:22

Not knowing how large your figure and table floats are, it's hard (impossible?) to diagnose the problem fully. (From the [scale=...] options, though, I'm surmising that the figures are quite large.) You could try changing some of LaTeX's float-placement parameters and check if the float placement problems are at least partially alleviated. Start with the following settings:

\renewcommand\topfraction{0.85}
\renewcommand\bottomfraction{0.85}
\renewcommand\textfraction{0.1}
\renewcommand\floatpagefraction{0.85}

-