# exam/geometry: How to use \iflastpage to change the geometry of the last page?

How to make \iflastpage{\newgeometry{bottom=40mm}}{} work to have a specific bottom offset for only the last page?

\documentclass{exam}
\usepackage[14pt]{extsizes}
\usepackage{lipsum}

\usepackage[bottom=20mm]{geometry}

\newcommand{\myfooter}{\iflastpage{%
{\centering\large End of the Exam}%
\vspace{5pt}}{}
\hrule\vspace{5pt}
Instructors}

\firstpagefooter{}{\myfooter}{}
\runningfooter{}{\myfooter}{}

\iflastpage{\newgeometry{bottom=40mm}}{}

\begin{document}
\lipsum[1-5]
\end{document}

• You will run into problems if the page is nearly full: if you shorten it the text will wander to the next page and the number of the last page will oscillate. – Ulrike Fischer Nov 5 '19 at 8:45
• @UlrikeFischer Do you mean that it is not stable to use \iflastpage to change the geometry of the last page? If yes, is there any other way to do so? – Diaa Nov 5 '19 at 9:05
• I would simply put the text "End of the Exam" at the end of the document. – Ulrike Fischer Nov 5 '19 at 9:07
• @UlrikeFischer Unfortunately, this document resulted in this ugly output where End of the Exam is not placed just above the footer horizontal rule. – Diaa Nov 5 '19 at 9:17

You can add “End of Exam” so it takes no vertical space. You might also add \vspace*{20pt} at the very end of the text in order to ensure no overlap.

In any case, the text should be checked and possibly modified to fit in the required number of pages, so manual work is needed anyway.

\documentclass{exam}
\usepackage[14pt]{extsizes}
\usepackage{lipsum}

\usepackage[bottom=20mm]{geometry}

\newcommand{\myfooter}{
\iflastpage{\raisebox{5pt}[0pt][0pt]{\large End of the Exam}}{}%
\hrule\vspace{5pt}%
Instructors%
}

\firstpagefooter{}{\myfooter}{}
\runningfooter{}{\myfooter}{}

\begin{document}
\lipsum[1-5]
\end{document}


If you set the bottom margin to 25mm everything is OK. Now no need to use newgeometry command.

\documentclass{exam}
\usepackage[14pt]{extsizes}
\usepackage{lipsum}

\usepackage[bottom=25mm]{geometry} % <-- changed to 25 mm.

\newcommand{\myfooter}{\iflastpage{%
{\centering\large End of the Exam}%
\vspace{5pt}}{}
\hrule\vspace{5pt}
Instructors}

\firstpagefooter{}{\myfooter}{}
\runningfooter{}{\myfooter}{}

%\iflastpage{\newgeometry{bottom=40mm}}{}

\begin{document}
\lipsum[1-15]
\end{document}


• If you use 1-20 for lipsum, 'Instructors' is cut off on the final page. – cfr Nov 5 '19 at 4:17
• Thanks, but I need the word Instructors to be spaced from the page bottom edge equally in both last and second-to-last pages. – Diaa Dec 7 '19 at 23:13