# Different margins for second page and onwards

I am aware of similar questions, however I would like the same functionality with

\newgeometry{a4paper, left=35mm, right=35mm, top=30mm, bottom=30mm}

or afterpage package..

to happen when there is a new page... I do not know when and if there are multiple pages, as this is dependent on the amount of content.

basically

first page

\geometry{a4paper, left=35mm, right=35mm, top=51mm, bottom=30mm}

second page (dynamic when it starts

\newgeometry{a4paper, left=35mm, right=35mm, top=30mm, bottom=30mm}

Here is a solution.

\documentclass{article}
\usepackage{lipsum}% just for the example

\usepackage{geometry}
\geometry{a4paper, left=35mm, right=35mm, top=51mm, bottom=30mm}

\usepackage{etoolbox}

\newlength\newtop
\setlength{\newtop}{21mm}

\makeatletter
\patchcmd\@outputpage{\global \@colht \textheight}{%
\global\textheight=\dimexpr\textheight+\newtop\relax%
\global\topmargin=\dimexpr\topmargin-\newtop\relax%
\global\@colht\textheight%
\global\newtop\z@}{}{\err}
\makeatother
\begin{document}
\lipsum[1-30]
\end{document}


Explanation

\patchcmd[<prefix>]{<command>}{<search>}{<replace>}{<success>}{<failure>}


etoolbox documentation

This command extracts the replacement text of a <command>, replaces <search> with <replace>, and reassembles the <command>.

We use \patchcmd to redefine the internal command \@outputpage:

\global\textheight=\dimexpr\textheight+\newtop\relax%


the new text height is the old text height plus \newtop=21mm

\global\topmargin=\dimexpr\topmargin-\newtop\relax%


the new top margin is the old top margin minus \newtop=21mm

Note \topmargin is an internal command topmargin=top(geometry)-1in-headheight-headsep

\global\@colht\textheight%


\@colht=\textheight \@colht is internal command used by latex for as \textheight

\global\newtop\z@


we set \newtop=0(uniteoflength) otherwise textheight and topmargin will be changed in every use of \@outputpage (i.e every page)

• Dunno what this is, but it works! could you explain to me what each line actually does? – dimitrieh May 20 '16 at 13:33