Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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  

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.