2

Why is no page number shown on the page after the one generated by afterpage?

\documentclass{article} 
\usepackage{afterpage, geometry, lipsum}

\begin{document} 
\lipsum

\afterpage{%
\clearpage
\newgeometry{margin=1cm}
\thispagestyle{empty}
foo
\restoregeometry
\clearpage
}

\lipsum
\end{document}

Thank you!

1
  • I'd think that \afterpage is needed in 0.00001% of documents and \newgeometry needed in a similar amount, so the number of documents needing \newgeometry in \afterpage should be ... small.... Nov 13, 2015 at 16:21

1 Answer 1

5

A page number is not shown because you set \thispagestyle{empty}. If you remove that line the page number will be set at the bottom center of the page, but \newgeometry{margin=1cm} pushes it off the page.

To restore the original page geometry after the \afterpage, use \aftergroup\restoregeometry (thanks to this answer).

\documentclass[a4paper]{article} 
\usepackage{afterpage, geometry, lipsum}
\documentclass{article} 
\usepackage{afterpage, geometry, lipsum}
\begin{document} 
\lipsum
\afterpage{%
\clearpage
\thispagestyle{empty}
\newgeometry{margin=4cm}
foo
\clearpage
\aftergroup\restoregeometry %
}
\lipsum
\end{document}
3
  • Having no page number on the "foo" page is intended. However, if I use margin=4cm the page number indeed shows up on the last page. Why is that? Shouldn't \restoregeometry followed by \clearpage set the geometry of the last page to the same than the first? margin=1cm should only be set for the "foo" page.
    – Sämy
    Nov 13, 2015 at 16:06
  • 1
    Replace \restoregeometry with \aftergroup\restoregeometry (see tex.stackexchange.com/a/40503/24974)
    – erik
    Nov 13, 2015 at 16:12
  • You're welcome. I had misunderstood your initial question, so I've edited my answer.
    – erik
    Nov 13, 2015 at 16:21

You must log in to answer this question.

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