# Latex Error: \begin{document} ended by \end{sidewaystable}

I get the following error when compiling my LaTeX source:

! LaTeX Error: \begin{document} ended by \end{sidewaystable}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.98


The table causing the problem, which is defined in chapter1.tex, and included in the main document by \include{chapter1}, is:

\afterpage{
\clearpage
\begin{sidewaystable}
\begin{center}
\scalebox{0.75}{
\begin{tabular}{p{4cm}|c|p{4cm}|p{5cm}l|ll|l|}
\hline
\multicolumn{3}{c|}{}
& \multicolumn{2}{c|}{Time Complexity}
& \multicolumn{2}{c|}{Space Complexity} \\
\hline
Author
& Year
& Method
& $m < n$
& $m = n$
& $m < n$
& $m = n$ \\
\hline
\hline
...
\hline
\end{tabular}
}
\caption{Time and space complexity of algorithms used to calculate Hermite Normal Form matrices measured in terms of the matrix dimension, $n$, by letting $M = O(n^c)$ for some constant $c$, and $m = O(n)$.  Such conversions will be denoted by $O^{\thicksim}$(*).}
\end{center}
\end{sidewaystable}
\clearpage
}


The main source file uses the report document class. It also uses the following packages:

\usepackage{uowthesis}
\usepackage{epsfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathdots}
\usepackage{color}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{epsf}
\usepackage{float}
\usepackage{multirow}
\usepackage{afterpage}
\usepackage{pgfplots}


Apart from some \newtheorem and \newcommand statements, there is nothing spectacular about the main source file that should cause it to behave this way unless, of course, the \afterpage statement (above) interferes with the \beforepreface and \afterpreface statements, also included in the main source.

Note that I have decided not to paste the main source file as sample code in this question due to space limitations. Also, due to breach of confidentiality, intellectual property, etc. However, I can elaborate on certain portions of the main source if requested and, if necessary.

# Modification: bill 3-JAN-2012 - Added sample main file.

Here's an abridged version of the main file that can be used to cause/show the problem. Hope it helps.

\documentclass[a4,12pt]{report}

\usepackage{uowthesis}
\usepackage{epsfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathdots}
\usepackage{color}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{epsf}
\usepackage{float}
\usepackage{multirow}
\usepackage{afterpage}
\usepackage{pgfplots}

\begin{document}

%
\title{Optimal Key Lengths and Digital Signatures}
\author{Vasilios Evangelos Tourloupis}
\dedicate{My Family}
\degree{Master of Computer Science}
\dept{School of Computer Science and Software Engineering}

\beforepreface
%\include{abstract}  % Abstract
%\include{acknowledgement}   % Acknowledgements}
%\include{papers}    % Publications

\afterpreface

\include{chapter1} % Introduction
\include{Chapter2} % Background
\include{Chapter3} % Efficient Self-Certified Signatures with Batch Verification
\include{chapter4} % Self-Certified Ring Signatures
\include{Chapter5} % Conclusion

%\bibliographystyle{alpha}
%\bibliography{thesis}   %\include{NoCites}   % Important references (probably not cited before)

\end{document}

-
Try compiling a minimal example. If you suspect that \afterpage is interfering, why not try commenting it out and seeing if you get the same error? –  Seamus Jan 2 '12 at 13:35
@Seamus - Can't include small example, as it would require pasting the entire style file defining the package uowthesis. Commenting out \afterpage alone did not solve the problem, however, commenting out the whole table did. Therefore, it must be a problem with the table (which I highly doubt as this is a straight copy and paste from an article class paper that had no problems compiling). –  Bill Jan 2 '12 at 13:49
Does compiling it with table work instead of sidewaystable? If it does, this might be because of a redefinition/undefinition of the sidewaystable environment (probably in your custom thesis class). –  recluze Jan 2 '12 at 13:54
Bill, you say that a MWE would require uowthesis (which means that the error does not occur without it), so it seems it's the main reason for the problem you have. So we need the uowthesis package for an analysis of the problem. –  Axel Sommerfeldt Jan 2 '12 at 15:24
The package uowthesis.sty is old and creates many problems. In particular the definition of \@xfloat is buggy. Commenting it makes the problem disappear. However I discourage using such a buggy package. –  egreg Jan 2 '12 at 21:13

uowthesis is an old LaTeX style written for LaTeX 2.09. Especially the redefinition of \@xfloat is not compatible to LaTeX2e. As a workaround one can save the definition of \@xfloat before including the uowthesis style, and do a proper redefinition afterwards:

\documentclass[a4paper,12pt]{report}

% Save \@xfloat
\makeatletter
\let\@xfloat@ORI\@xfloat
\makeatother

\usepackage{uowthesis}

% Redefine \@xfloat in a way which works with LaTeX2e
\makeatletter
\def\@xfloat#1[#2]{%
\@xfloat@ORI{#1}[{#2}]%
\def\baselinestretch{1}\@normalsize} % This line taken from uowthesis
\makeatother

\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
\centering
\begin{tabular}{p{4cm}|c|p{4cm}|p{5cm}l|ll|l|}
\hline
\multicolumn{3}{c|}{}
& \multicolumn{2}{c|}{Time Complexity}
& \multicolumn{2}{c|}{Space Complexity} \\
\hline
%          ...
\hline
\end{tabular}
\caption{Time and space complexity of algorithms...}
\end{sidewaystable}

\end{document}


Note that this isn't up-to-date coding either. A better approach would be using the setspace package for that purpose. The setspace enables single spacing for floating environments and footnotes automatically, so no need to patch \@xfloat and \@footnotetext as done in uowthesis.

-
Thanks for that! It solved the problem! Seems like UoW will have to review their style file.... –  Bill Jan 2 '12 at 21:04
Yes, definitely. –  Axel Sommerfeldt Jan 2 '12 at 21:11
@Bill: LaTeX2e was released in 1994! So after nearly two decades they definitely should "review" their templates. –  Martin Schröder Jan 6 '12 at 9:09

You probably opened something that you didn't close. (It could be in the source doc, or it could be in the expansion of some macro.)

Comment out things until you have something that works. Then add back. At that point you know the offending piece.

-
@JimHeffron - That's probably something I will have to painstakingly do. I was hoping that by posting to the group, somebody would have seen the problem before, and therefore know how to resolve it quickly. Unfortunately, that does not appear to be the case. Thanks for the advice anyway. –  Bill Jan 2 '12 at 14:09
Using dichotomy, you should be able to see quickly what line is the wrongdoer. –  Jean-Christophe Dubacq Jan 2 '12 at 14:26