[Tex/LaTex] How to Override the Default Float Restrictions of Table and Figure

floatspositioningrotating

In brief, the [h!] option to override the default float restrictions for tables and figures does not appear to work.

I am trying to insert a table that takes up a whole page. Due to its size, I have had to define it as a sidewaystable as follows:

\begin{sidewaystable}[h!]
  \begin{center}
    \begin{tabular}{p{4cm}|p{4cm}|p{4cm}|p{5cm}|}
      \hline
      Column 1 & Column 2 & Column 3 & Column 4 \\
      \hline
      \hline
        .
        .
        .
      \hline
    \end{tabular}
    \caption{A Caption}
  \end{center}
\end{sidewaystable}

No matter what I try to do, LaTeX always places it at the end of the document, after my bibliography (i.e. references). What's worse is that any table that I define after this, no matter how big or small, is also placed at the end of the document (after the problematic table).

I seem to have a similar problem with figures. While the [h!] option places some figures immediately after the paragraph I have referenced them in (as expected), LaTeX places other figures one or two pages following the referencing paragraph.

If it helps any, I am using the following document class:

\documentclass[JMC]{degruyter-journal}   % Journal of Mathematical Cryptology

I am also using the following packages:

\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{epsfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathdots}
\usepackage{color}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{epsf}
\usepackage{float}
\usepackage[lined,ruled]{algorithm2e}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

Best Answer

I've found the following set of instructions works well in the circumstances you describe; I use the \afterpage command provided by the afterpage package.

...
\afterpage{\clearpage
\begin{sidewaystable} % no need for the [h] or even [h!] specifier
\centering % better than \begin{center} ... \end{center}
\begin{tabular}...
...
\end{tabular}
\caption{xyz} \label{tab:xyz}
\end{sidewaystable}
\clearpage } % note the "}" to denote the end of the argument of \afterpage
...

The key is the use of \clearpage commands both before and after the sideways{figure/table} environment.

Related Question