# Can I make the geometry of the first page different from other pages?

I want to make the top margin in the first page larger than other pages. The code I use is:

\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{
top=8cm,
hmargin=1in,
}
\usepackage{mwe}
\usepackage{afterpage}
\begin{document}
\lipsum
\afterpage{
\newgeometry{
top=3cm
}
}
\lipsum
\end{document}


The output pdf has the same page layout for every page and I don't get what I want. How can I have the different layout for the first page?

• The first page is your title page i guess? You can always add a negative vertical space. Or use the title page as a separate file and include the pdf. But don't mess around with afterpage. Sep 4 '18 at 11:07

Two things to be considered:

First, the \afterpage command expands its contents in a group, so changes are reverted unless they are \global. The effect of \newgeometry is local, so nothing happens when you execute it inside \afterpage.

Second, the \afterpage command inserts its argument after the current page has ended, so if you do \lipsum\afterpage{<something>}\lipsum, the <something> will be inserted in the page that follows the end of the first \lipsum (which is, in this case, past the middle of the document).

To work around these issues I used \restoregeometry instead, which is only one token, so it can be easily inserted \aftergroup, and I moved the call to \afterpage right at the beginning of the document, so it will take effect once the first page ends.

\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{
top=3cm,
hmargin=1in,
}
\usepackage{mwe}
\usepackage{afterpage}
\begin{document}
\newgeometry{top=8cm}
\afterpage{\aftergroup\restoregeometry}
\lipsum
\lipsum
\end{document}

• Thanks for your answer, it works. Can you explain why the \aftergroup command is needed? Sep 4 '18 at 11:10
• @Ice0cean \aftergroup inserts the next token after one \endgroup (or } or \egroup), which is needed here. I added an explanation. Sep 4 '18 at 11:12