0

I am having trouble using \afterpage in combination with some figures+captions that are too adjusted or directly exceed the document's margins (I assume that this is the cause of \afterpage not behaving as usual). I don't mind these figures exceeding the margins, but I need to place them close to where they are referenced and they keep being pushed to the end of the document, leaving large empty spaces. Does anybody have a workaround?

The image is an example of what I get, I would like the figure and the caption to be on the second page, and the remaining text in the last page. I have searched the forum, but could not find a suitable solution.

Thank you!

enter image description here

MWE:

\documentclass[a5paper,twoside,openright]{report}

\usepackage{lipsum}

\usepackage{showframe}

\usepackage{afterpage}

\usepackage{mwe}

\usepackage[fontsize=9pt]{scrextend}

\begin{document}

\lipsum[2-3]

*********After page goes here**********

% It works with a short caption:
%
%\afterpage{%
%
%\begin{figure*} 
%   
%   \makebox[\textwidth][c]{
%   
%   \includegraphics[width=\textwidth]{example-image}}
%   
%   \caption[A caption]{Short caption.}
%   
%\end{figure*}
%}

% It does not work with a long caption:

\afterpage{%

\begin{figure*}
    
    \makebox[\textwidth][c]{
    
    \includegraphics[width=\textwidth]{example-image}}
    
    \caption[A caption]{\lipsum[1]}
    
\end{figure*}
}

\lipsum[2-3]

\end{document}
1
  • using afterpage that way can only ever make the figure go later in the document. I wouldn't use \afterpage (I wrote it, I know what it does:-) but if you do use it for figures I assume you meant to have \clearpage at the end of the argument Sep 28, 2022 at 13:03

1 Answer 1

1

In the form you used, the \afterpage could only make the float be further from the point of insertion, or at best have no effect as it delays the insertion but then floats as usual. I would guess you intended \clearpage after \end{figure} but I would not use \afterpage at all here.

Also as it is a single column document, use figure not figure* (although they are the same) and the \makebox does nothing as the image is alreeady scaled to \textwidth.

The figure will float until forced out by \clearpage as it is too large, latex warns

 LaTeX Warning: Float too large for page by 13.15417pt on input line 43.

\afterpage does not change that.

You could use \clearpage (or \afterpage{\clearpage}) but I would simply make the float smaller, 14pt is enough as shown by the warning, then ensure it is not a top float, so the negative space will not over-print following text.

enter image description here

\documentclass[a5paper,twoside,openright]{report}

\usepackage{lipsum}

\usepackage{showframe}

\usepackage{afterpage}

\usepackage{mwe}

\usepackage[fontsize=9pt]{scrextend}

\begin{document}

\lipsum[2-3]

*********After page goes here**********


\begin{figure}[bp]
        
    \includegraphics[width=\textwidth]{example-image}
    
    \caption[A caption]{\lipsum[1]}
    
\vspace{-14pt}
\end{figure}


\lipsum[2-3]

\end{document}
1
  • Thank you for the very detailed answer, David. I have learned a lot. :)
    – iss
    Sep 28, 2022 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .