Edit: I have found a smaller minimum working example, which is now included!
I'm working on creating a tool for creating an automatic latex document from a c++ header file. This works quite well, and I have defined some \newcommand to help reduce the size of the autogenerated file, as a lot of repetition happens. The file is mostly sequential sections of tables, a figure and 3-4 lines of text.
I use the fancyhdr package and have both a header and a footer. I also use the longtables package to allow for tables that are both long, and so they aren't being placed with a lot of space in between.
Now.... at one point something odd happens. For some reason, latex allows the creation of a new table, right on top of my footer, but only sometimes. At other times it makes a perfect seperation of two parts of a longtable, and continues on the next page.
I compile using pdflatex and texniccenter ver. 1 release candidate 1. Since my code is quite large even for a minimum working example, I don't know if I should post it here, but here goes. All real data has been removed, in case you were wondering

Code: Select all
\documentclass[a4paper,10pt]{article}
\usepackage[latin1]{inputenc} %Dansk tegnsætning
\usepackage[english]{babel} %Dansk orddeling
\usepackage[T1]{fontenc} %Valg af font
\usepackage{longtable}
\usepackage{setspace}
\usepackage{lastpage}
\usepackage{multirow}
\usepackage[pdftex]{color,graphicx} %Indsættelse af grafik
\usepackage{fancyheadings}
\usepackage{colortbl}
\usepackage[titles]{tocloft}
\input{doc_setup}
%% Start the latex document
\begin{document}
\section{DEFINITIONS}
\subsection{Overview}
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk kkkkkkkks kkkk k fasdf asdrfsaer as fas df aser as asd fas df asdf asd f asd fas d f asf asd f asdf asd f asdfas dr awe rasd f as d f acv xc vxcv
kkkkkkkkk kkkkkkkkkkkkkk kkkkkkkkk kkkkkkkkkkkkk kkkkkkkks kkkk k fasdf asdrfsaer as fas df aser as asd fas df asdf asd f asd fas d f asf asd f asdf asd f asdfas dr awe rasd f as d f acv xc vxcv sd f asd fas d f asf asd f asdf asd f asdfas dr awe rasd f as d f acv xc vxcv
\footnotetext[1]{These records are available by subscription only.}
\begin{spacing}{1.2}
\begin{center}
\begin{longtable}{|p{2.5cm}|p{8cm}|}
\caption[Definitions]{Definitions} \\
\blackcell{Type} & \blackcell{Description}\\\hline
\endfirsthead
\caption[]{Definitions (continued)} \\
\blackcell{Type} & \blackcell{Description}\\\hline
\endhead
\endfoot
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
1000-1999 & Reserved\\\hline
\end{longtable}
\end{center}
\end{spacing}
\subsection{Point}
\textbf{Description:} Reference point Information.
\\\\
\notebox{kkkkkkkkk kkkkkkkkkkkkkk kkkkkkkkk kkkkkkkkkkkkk kkkkkkkks kkkk k fasdf asdrfsaer as fas df aser as asd fas df asdf asd f asd fas d f asf asd f asdf asd f asdfas dr awe rasd f as d f acv xc vxcv d f asf asd f asdf asd f asdfas dr awe rasd f as d f acv xc vxcvd f asf asd f asdf asd f asdfas dr awe rasd f a.}
\textbf{Data Definition:}
\ddtabRTH
\msgtabstart
\caption[1000]{1000} \\
\msgtabheader
\caption[]{1000 (continued)}\\
\msgtabheaderend
1asdfjkasdæfljkasdlæfkjas dfklæja asdfækl& b & c\\\hline
1asdfjkasdæfljkasdlæfkjas dfklæja asdfækl& b & c\\\hline
1asdfjkasdæfljkasdlæfkjas dfklæja asdfækl& b & c\\\hline
1& b & c\\\hline
\msgtabend
\subsection{1000 }
\textbf{Description:} data.
\\\\
\textbf{Data Definition:}
\ddtabRTH
\msgtabstart
\caption[1000]{1000 } \\
\msgtabheader
\caption[]{1000}\\
\msgtabheaderend
a & b & c\\\hline
a & b & c\\\hline
a & b & c\\\hline
a & b & c\\\hline
a & b & c\\\hline
a & b & c\\\hline\msgtabend
\end{document}
Code: Select all
%% Helper functions
\newcommand{\tm}{$^{\textrm{tm}}$}
\newcommand{\dgr}{$^{\circ}$}
%% Header and Footer setup
\setlength{\headwidth}{16cm}
\setlength{\headrulewidth}{0.0pt}
\setlength{\plainfootrulewidth}{0.4pt}
\setlength{\footrulewidth}{0.4pt}
\lfoot{\hspace{.2cm}Document}
\cfoot{ Page \thepage \hspace{.1cm}of \pageref{LastPage}}
\rfoot{\today\hspace{.2cm}}
\lhead{}
\chead{\vspace{-1cm}\renewcommand\arraystretch{1.5}\large
\begin{tabular}{|p{3cm}|p{4cm}|p{2cm}|p{2cm}|p{3cm}|}
\hline
\multirow{2}{3cm}{\vspace{-.35cm}} & Document Number: & 1& Version: & 1 \\\cline{2-5}
& Document Title: & \multicolumn{3}{|l|}{Title} \\\hline
\end{tabular}
}
\rhead{}
\pagestyle{fancyplain}
%% Page layout
\setlength{\textheight}{205mm}
\setlength{\topmargin}{5mm}
\setlength{\textwidth}{160mm}
\setlength{\hoffset}{1.5cm}
\setlength{\oddsidemargin}{-1.5cm}
\setlength{\evensidemargin}{-1cm}
%% Setting font to Arial
\usepackage[scaled]{uarial}
\renewcommand{\rmdefault}{phv} % Arial
\renewcommand{\sfdefault}{phv} % Arial
%% Using hyperlinks in the pdf document
\usepackage[colorlinks,pdftex]{hyperref} % for DVIPDFM
\hypersetup{colorlinks=true,urlcolor=black,urlbordercolor={1 1 1}}
\hypersetup{citecolor=blue,linkcolor=black,anchorcolor=red}
\hypersetup{pdfpagemode=UseOutlines,bookmarksnumbered=true}
\hypersetup{bookmarksopen=true}
%% Line spacing and indentation
\linespread{1.1}
\parindent=0in
\setlength{\parskip}{.2cm}
\newenvironment{packed_item}{
\begin{itemize}
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}
}{\end{itemize}}
%% Table type setup
\usepackage{array}
\newcolumntype{x}[1]{>{\centering}m{#1}}
\newcolumntype{y}[1]{>{\raggedleft}m{#1}}
\definecolor{lightblue}{rgb}{0.53,0.80,1}
\newcommand{\blackcell}[1]{\cellcolor[gray]{0}\color{white}\textbf{#1}}
\newcommand{\lightbluecell}[1]{\cellcolor[rgb]{0.53,0.80,1}\Large{\textit{\textbf{#1}}}}
%% Change name and appearance of the table of contents
\addto\captionsenglish{\renewcommand{\contentsname}{Table of Contents}}
\renewcommand{\cftsecnumwidth}{.9cm}
\renewcommand{\cftsubsecnumwidth}{1.2cm}
\renewcommand{\cftsubsubsecnumwidth}{1.2cm}
\newcommand{\appsection}[1]{\section[\hspace{1.9cm}#1]{#1}}
% Document information
\title{\vspace{-3cm}Document\vspace{8cm}}
\author{Henrik Andresen}
\date{\today}
%% Autocreation of noteboxes
\newcommand{\notebox}[1]{
\begin{table}[!th]
\centering
\renewcommand\arraystretch{1.5}
\begin{tabular}{ |rm{14cm}l| }
\hline
\lightbluecell{} & \centering\lightbluecell{Note} & \lightbluecell{}\\\hline
& #1 &\\\hline
\end{tabular}
\end{table}
\vspace{.1cm}
}
%% Autocreation of 3 tables
\newcommand{\ddtabRTH}{\begin{table}[!th]
\centering
\renewcommand\arraystretch{1.5}
\begin{tabular}{ |x{1.5cm}|x{1.5cm}|x{5cm}|x{3cm}|y{1.3cm} m{0cm}| }
\hline
DRF & \cellcolor[gray]{0.85} RTH & RD & OD & DRF &\\
\hline
\end{tabular}
\end{table}}
\newcommand{\ddtabRD}{\begin{table}[!th]
\centering
\renewcommand\arraystretch{1.5}
\begin{tabular}{ |x{1.5cm}|x{1.5cm}|x{5cm}|x{3cm}|y{1.3cm} m{0cm}| }
\hline
DRF & RTH & \cellcolor[gray]{0.85} RD & OD & DRF &\\
\hline
\end{tabular}
\end{table}}
\newcommand{\ddtabOD}{\begin{table}[!th]
\centering
\renewcommand\arraystretch{1.5}
\begin{tabular}{ |x{1.5cm}|x{1.5cm}|x{5cm}|x{3cm}|y{1.3cm} m{0cm}| }
\hline
DRF & RTH & RD & \cellcolor[gray]{0.85} OD & DRF &\\
\hline
\end{tabular}
\end{table}}
\newcommand{\docimage}[2]{
\begin{figure}[!ht]
\centering
\includegraphics[width=.80\textwidth]{#1}
\caption{#2}
\end{figure}
}
%% Autogenerate start and end of longtables. Reduce code-size
\renewcommand\arraystretch{1.2}
\newcommand{\msgtabstart}{\begin{spacing}{1.2}\begin{center}\begin{longtable}{|p{5cm}|p{1.5cm}|p{8cm}|}}
\newcommand{\msgtabheader}{\hline\blackcell{Name} & \blackcell{Size} & \blackcell{Description}\\\hline\endfirsthead}
\newcommand{\msgtabheaderend}{\hline\blackcell{Name} & \blackcell{Size} & \blackcell{Description}\\\hline\endhead\endfoot}
\newcommand{\msgtabend}{\end{longtable}\end{center}\end{spacing}}
%% Change size of figure text size
\newcommand{\captionfonts}{\footnotesize}
\makeatletter % Allow the use of @ in command names
\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{{\footnotesize{#1:} \scriptsize{#2}}}%
\ifdim \wd\@tempboxa >\hsize
{\footnotesize{#1:} \scriptsize{#2}\par}
\else
\hbox to\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
\makeatother % Cancel the effect of \makeatletter
\hfuzz 10pt % Don't bother to report over-full boxes if over-edge is < 2pt
%% New framebox
\newsavebox{\fmbox}
\newenvironment{fmpage}[1]
{\begin{lrbox}{\fmbox}\begin{minipage}{#1}}
{\end{minipage}\end{lrbox}\fbox{\usebox{\fmbox}}}
Have anybody ever experienced something similar, and what did you do?
Thank you all
Henrik