3

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}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm,headheight=1cm,headsep=1cm,footskip=1cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{color}
\usepackage{babel}
\usepackage{array}
\usepackage{float}
\usepackage{graphicx}
\usepackage{parskip}
\usepackage[bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
{hyperref}
\hypersetup{pdftitle={XXXXXX},
pdfauthor={Autogenerated by XXXXXX}}
\providecommand{\tabularnewline}{\\}
\usepackage{color}
\lhead{XXXXXX}
\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?

qubyte
  • 17,299
Tom
  • 185
  • 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
  • 3
    See for example http://tex.stackexchange.com/questions/39017/how-to-influence-the-position-of-float-environments-like-figure-and-table-in-lat, http://tex.stackexchange.com/questions/279/how-do-i-ensure-that-figures-appear-in-the-section-theyre-associated-with, http://tex.stackexchange.com/questions/2275/keeping-tables-figures-close-to-where-they-are-mentioned and http://tex.stackexchange.com/questions/8625/force-figure-placement-in-text – Torbjørn T. Dec 22 '11 at 15:52

2 Answers2

3

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]{
    \addtocounter{figure}{1}
    {\center Figure \arabic{figure} #1\\ }
    \addcontentsline{lof}{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.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
  • 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
1

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}
Mico
  • 506,678