[Tex/LaTex] How to avoid text overflowing below bottom margin

geometrymargins

My document contains a title page followed by some text. In order to create my title page, I have to change the page margins on the title page using \newgeometry, and after the title page I return to the usual default margins using \restoregeometry. It includes graphics, uses Tikz, and uses a new environment called changemargin whose code is placed at the beginning of the code before \begin{document}.

MWE:

\documentclass[10pt, a4paper, titlepage, draft]{article}
% USING DRAFT BECAUSE WE DO NOT HAVE THE PDFs TO BE INCLUDED
\usepackage{geometry}
\usepackage{tikz}
\usepackage{graphicx}

\usetikzlibrary{calc}% ADDED !!!!!

\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
}%
\item[]}
{\end{list}}

\begin{document}

\begin{titlepage}

\newgeometry{left=6.75cm, right=1.25cm, top=1.25cm, bottom=1.25cm}

\mbox{}\hfill
\begin{minipage}[c]{8cm} 
\flushright \textbf{University of ...}
\end{minipage}%
\hspace{0.5cm} % your specified distance
\begin{minipage}[c]{2.5cm}
\flushright \includegraphics[width=2.50cm]{logo.pdf}
\end{minipage}%

\begin{tikzpicture}[overlay, remember picture]

\useasboundingbox [fill=blue!20] ($ (current page.south west) + (1, 1)  $) rectangle ($ (current page.north west) + (6.75, -1) $) ;
\draw [line width=0.01mm, blue] ($ (current page.north west) + (1, -1)  $) rectangle ($ (current page.south east) + (-1, 1) $) ; 
\draw ($ (current page.north west) + (9.625, -4.00)  $) -- ($ (current page.north east) + (-1.25, -4.00)  $) ;
\draw ($ (current page.south west) + (9.625, 4.00)  $) -- ($ (current page.south east) + (-1.25, 4.00)  $) ;

\node[anchor=south west, %anchor is upper left corner of the graphic
xshift=1.125cm, %shifting around
yshift=1.125cm]  
at (current page.south west) %left upper corner of the page
{\includegraphics[width=5.25cm]{logo2.pdf}}; 

\end{tikzpicture}

\begin{changemargin}{0cm}{-0.25cm}

\centering

\vspace*{\baselineskip}
\vspace*{\baselineskip}

\rule{127mm}{1.6pt}\vspace*{-\baselineskip}\vspace*{2pt}    
\rule{127mm}{0.4pt}\\[\baselineskip]
\vspace*{\baselineskip}
{\large \textbf{Title}}\\[\baselineskip]
{ Subtitle}\\[0.2\baselineskip]
\rule{127mm}{0.4pt}\vspace*{-\baselineskip}\vspace{3.2pt}
\rule{127mm}{1.6pt}\\[\baselineskip]
\vspace*{\baselineskip}

\end{changemargin}

\mbox{} \vfill \hfill
\begin{minipage}[c]{8cm}
\flushright \textbf{Faculty of Science}
\end{minipage}%
\hspace{0.5cm} % your specified distance
\begin{minipage}[c]{2.5cm}
\flushright \includegraphics[width=2.50cm]{logo3.pdf}
\end{minipage}%

\restoregeometry

\end{titlepage}

\newpage

article text

\end{document}

However, the text on the first page overflows into the bottom margin of the document. This does not happen for all the other pages, only the first one.

What have I done wrong?

(I know my question is similar to this one:

Margin overflow when setting the geometry \AtBeginDocument

but the answer given there doesn't solve my problem.)

Best Answer

\newgeometry affects the following page, so moving it to be before \begin{titlepage} will ensure that it effects the title page.

And since you probably want pages after the title page to have the original geometry, moving \restoregeometry to be after \end{ttilepage}, and before \newpage will make it effective on the first page of the document.

Notes:

Code:

\documentclass[10pt, a4paper, titlepage, draft]{article}
% USING DRAFT BECAUSE WE DO NOT HAVE THE PDFs TO BE INCLUDED
\usepackage{geometry}
\usepackage{tikz}
\usepackage{graphicx}

\usetikzlibrary{calc}% ADDED !!!!!
\usepackage{showframe}% ADDED !!!!!
\usepackage{lipsum}% ADDED !!!!!

\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
}%
\item[]}
{\end{list}}

\begin{document}
\newgeometry{left=6.75cm, right=1.25cm, top=1.25cm, bottom=1.25cm}
\begin{titlepage}

%\newgeometry{left=6.75cm, right=1.25cm, top=1.25cm, bottom=1.25cm}

\mbox{}\hfill
\begin{minipage}[c]{8cm} 
\flushright \textbf{University of ...}
\end{minipage}%
\hspace{0.5cm} % your specified distance
\begin{minipage}[c]{2.5cm}
\flushright \includegraphics[width=2.50cm]{logo.pdf}
\end{minipage}%

\begin{tikzpicture}[overlay, remember picture]

\useasboundingbox [fill=blue!20] ($ (current page.south west) + (1, 1)  $) rectangle ($ (current page.north west) + (6.75, -1) $) ;
\draw [line width=0.01mm, blue] ($ (current page.north west) + (1, -1)  $) rectangle ($ (current page.south east) + (-1, 1) $) ; 
\draw ($ (current page.north west) + (9.625, -4.00)  $) -- ($ (current page.north east) + (-1.25, -4.00)  $) ;
\draw ($ (current page.south west) + (9.625, 4.00)  $) -- ($ (current page.south east) + (-1.25, 4.00)  $) ;

\node[anchor=south west, %anchor is upper left corner of the graphic
xshift=1.125cm, %shifting around
yshift=1.125cm]  
at (current page.south west) %left upper corner of the page
{\includegraphics[width=5.25cm]{logo2.pdf}}; 

\end{tikzpicture}

\begin{changemargin}{0cm}{-0.25cm}

\centering

\vspace*{\baselineskip}
\vspace*{\baselineskip}

\rule{127mm}{1.6pt}\vspace*{-\baselineskip}\vspace*{2pt}    
\rule{127mm}{0.4pt}\\[\baselineskip]
\vspace*{\baselineskip}
{\large \textbf{Title}}\\[\baselineskip]
{ Subtitle}\\[0.2\baselineskip]
\rule{127mm}{0.4pt}\vspace*{-\baselineskip}\vspace{3.2pt}
\rule{127mm}{1.6pt}\\[\baselineskip]
\vspace*{\baselineskip}

\end{changemargin}

\mbox{} \vfill \hfill
\begin{minipage}[c]{8cm}
\flushright \textbf{Faculty of Science}
\end{minipage}%
\hspace{0.5cm} % your specified distance
\begin{minipage}[c]{2.5cm}
\flushright \includegraphics[width=2.50cm]{logo3.pdf}
\end{minipage}%

\end{titlepage}

\restoregeometry
\newpage

\lipsum[1-12]% Added

\end{document}