[Tex/LaTex] afterpage clashes with restoregeometry from the geometry package

afterpagefloatrowgeometrygraphics

I'm writing my thesis and have used the geometry package to control the size of the text body so that it follows 'good' typesetting practices as described in the KOMA-script documentation.

Many of my figures are full-page floats that are taller than the text height. Consequently I have been using the newgeometry/restoregeometry and afterpage commands to adjust the page layout and ensure that the figure is appropriately placed in the document.

This works fine except that on the page immediately following the figure, the text 'runs' into the bottom margin. I've have provided a MWE below. Note how the fourth page is formatted incorrectly. (I am using pdfLaTeX).

Does anyone know how to correct this behaviour? (or have an alternative method of accomplishing the same layout?)

It seems to me as though the restoregeometry command is not being executed correctly.

\documentclass{scrbook}
\usepackage{calc}
\usepackage[showframe]{geometry}

% Calculate type area for page 
\geometry{ bindingoffset = 8mm, 
           heightrounded = true, 
           body = {125mm, 125mm * 16 / 9},
           marginratio = {9:16, 9:16},
           marginparsep = 5mm,
           marginparwidth = 30mm,
           headsep = 10mm,
           headheight = 10mm,
           footskip = 15mm }

\KOMAoptions{fontsize = 11pt}
% Chapters open on right.
\KOMAoptions{open = right}
% \cleardoublepage command uses the empty page style
\KOMAoptions{cleardoublepage = empty}
% Don't typeset the Chapter and Appendix prefixes
\KOMAoptions{chapterprefix = false}
\KOMAoptions{appendixprefix = false}
% We also avoid having running heads and page numbers on float pages by using the  floatpage
% package to make float pages use the empty page style.
\usepackage{floatpag}
\floatpagestyle{empty}
\rotfloatpagestyle{empty}

% For dummy text
\usepackage{lipsum}
% 
\usepackage{afterpage}

% For good control of floats
\usepackage[demo]{graphicx}
\usepackage{floatrow}
\floatsetup{facing=yes, 
            capbesideposition={outside,center},
            footnoterule=none}
\floatsetup[table]{style=plaintop}
\floatsetup[subfigure]{style=plain}
% Allow floats to hang into the outer margin
\DeclareMarginSet{minhangoutside}{%
\setfloatmargins*{\relax}
    {\hfill\hskip-\marginparwidth\hskip-\marginparsep}%
}
\floatsetup[figure]{margins=minhangoutside}

% For control of caption formatting
\usepackage{caption}
\usepackage{subcaption}
\captionsetup{font=normal,
              format=hang,
              labelfont=normal,
              labelsep=colon}

% End Preamble
%
%------------------------------------------------------------------------
\begin{document}

\chapter{First Chapter}
%
\section{First Section}%
\lipsum%

% Add a full page figure. I want the preceeding page to be full of text so
% use the afterpage command. Also as the figure is taller than the page height 
% I use the newgeometry/savegeometry/restoregeometry commands.
%
\afterpage{%
\newgeometry{bindingoffset = 8mm, 
             body = {125mm, 125mm * 16 / 9 + 10mm + 15mm}, 
             headsep = 0mm, 
             footskip = 0mm}%
\savegeometry{extraheight}
%
\begin{figure}[pc]%
\centering%
\ffigbox%
        {\includegraphics*[width=160mm,height=20mm]{}%
        \vspace*{1ex}%

        \begin{subfloatrow}%
            \ffigbox[\FBwidth]%
                    {\includegraphics*[width=160mm,height=96.0mm]{}}%
                    {\caption{First sub-figure}}%
        \end{subfloatrow}%
        \vspace*{1ex}%

        \begin{subfloatrow}%
            \ffigbox[\FBwidth]%
                    {\includegraphics*[width=160mm,height=96.0mm]{}}%
                    {\caption{Second sub-figure }}%
        \end{subfloatrow}}%
        {\caption{Main caption of the figure. In reality this runs to two lines long so I'm just filling in space here with meaningless text.}}%
\end{figure} 
%
\restoregeometry%
}
%
% Next section
\section{Second Section}%
\lipsum%
%
\section{Third Section}%
\lipsum%

\end{document}

Best Answer

I don't think that you need afterpage and restoregeometry. Use negative space to move your graphic around and avoid overful box messages. E.g.

\section{First Section}%
\lipsum%

\begin{figure}[pc]%
\vspace{-2cm}%move up
\begin{minipage}[t][\dimexpr \textheight + 3cm]{\textwidth}
\centering%

\makebox[\linewidth]{\rule{1.1\textwidth}{\textheight}}
\caption{Main caption of the figure. In reality this runs to two lines long so I'm just filling in space here with meaningless text.}%

\end{minipage}
\vspace{-3cm}%avoid "float to large"
\end{figure}