[Tex/LaTex] How to change geometry for one page without using \newgeometry or \restoregeometry

geometrymargins

I am trying to establish one geometry for my first page (not a title page), and use another for the rest of the document. However, because I am trying to make a template, and thus do not want to rely on a user to put in \newgeometry or \restoregeometry in the text of the document, I would like to establish these geometries in the preamble. Is there any way to do this?

A minimum working example

\documentclass{article}
\usepackage{lecturenotes}

\usepackage{afterpage}

\thispagestyle{plain}


\begin{lecture}{01}{Sample Lecture Notes}{John Sam}{01/01/2000}{Mark John}{PHYSICS 124: Physics of Energy}

\afterpage{\newgeometry{top=2cm, bottom=2.5cm, outer=5.5cm, inner=2cm, heightrounded, marginparwidth=3.5cm, marginparsep=0.4cm, includeheadfoot}}


\end{lecture}
\theend

The style 'lecturenotes'

    \def\fileversion{1.0}
\def\filedate{2014/02/05}
\NeedsTeXFormat{LaTeX2e}


\usepackage{graphicx}
\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage[top=0.5cm, bottom=2.5cm, outer=5.5cm, inner=2cm, heightrounded, marginparwidth=3.5cm, marginparsep=0.4cm, includeheadfoot]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}

\newcommand{\handout}{
   \noindent
   \begin{center}
   \framebox{ \vbox{ \hbox to 13.5cm { {\bf {\course}} \hfill {Lecture \lecturenum\ -- \lecturedate} }
       \vspace{4mm}
       \hbox to 13.5cm { {\Large \hfill {\lecturetitle}  \hfill} }
       \vspace{2mm}
       \hbox to 13.5cm { {\it {Lecturer: \lecturer} \hfill {Notes by: \lecturescribe}} }
     }
   }
   \end{center}
   \vspace*{4mm}
}

\newenvironment{lecture}[6]{
    \begin{document}
    \global \def \lecturenum {#1}
    \global \def \lecturetitle {#2}
    \global \def \lecturescribe {#3}
    \global \def \lecturedate {#4}
    \global \def \lecturer {#5}
    \global \def \course {#6}
    \handout
}


\lhead{\lecturedate}
\chead{\lecturetitle}
\rhead{Lecture \lecturenum}
\lfoot{}
\cfoot{\thepage}
\rfoot{}

\newcommand{\theend}{\end{document}}

Best Answer

If all you want to do is change the top margin on the first page, you're doing it the hard way. Just use a negative \vspace to move the text up to wherever you want it. The use of handout and lecture makes me wonder if this is not part of an even more elaborate set-up, but, in principle, you could do something like this:

\newlength\toplen  
\newlength\fplen   
\newlength\fpgap    
\setlength{\fplen}{0.5cm}  
\setlength{\toplen}{\dimexpr2cm + \fplen\relax}   
\setlength{\fpgap}{\dimexpr\fplen - \toplen - \headheight - \headsep - \topsep  
- \partopsep\relax}

Then plug \toplen into geometry and \vspace*{\fpgap} into your \handout command. Note: this is really designed to give you only 0.5 cm between the top of the physical page and the top of the framebox. Your original geometry command would leave significantly more space.

Here's a complete example, slightly changed from yours above. (Mainly with respect to the not-advised hiding of \begin{document} and \end{document}; but I also made \lecture [a command] from the environment lecture.)

\documentclass{article}
\usepackage{filecontents}
% --------------------------------------------------------------------
\begin{filecontents*}{lecturenotes.sty}
\def\fileversion{1.0}
\def\filedate{2014/02/05}
\NeedsTeXFormat{LaTeX2e}

\RequirePackage{graphicx}
\RequirePackage{amsmath,amssymb,amsthm,amsfonts}

% Some lengths
\newlength\toplen
\newlength\fplen
\newlength\fpgap
\setlength{\fplen}{0.5cm}
\setlength{\toplen}{\dimexpr2cm + \fplen\relax}
\setlength{\fpgap}{\dimexpr\fplen - \toplen - \headheight - \headsep - \topsep - \partopsep\relax}

\RequirePackage[showframe, top=\toplen, %
bottom=2.5cm, outer=5.5cm, inner=2cm, heightrounded,
marginparwidth=3.5cm, marginparsep=0.4cm, includeheadfoot]{geometry}

\RequirePackage{fancyhdr}
\pagestyle{fancy}
\lhead{\lecturedate}
\chead{\lecturetitle}
\rhead{Lecture \lecturenum}
\lfoot{}
\cfoot{\thepage}
\rfoot{}

\newcommand{\handout}{%
  \noindent
  \vspace*{\fpgap}%
  \begingroup
  \par
  \centering
  \framebox{ \vbox{ \hbox to 13.5cm { {\bf {\course}}
        \hfill {Lecture \lecturenum\ -- \lecturedate} }
      \vspace{4mm}
      \hbox to 13.5cm { {\Large \hfill {\lecturetitle}  \hfill} }
      \vspace{2mm}
      \hbox to 13.5cm { {\it {Lecturer: \lecturer} \hfill
          {Notes by: \lecturescribe}} }
    }
  }
  \par
  \endgroup
  \vspace*{4mm}%
  \par\ignorespacesafterend
}

\newcommand{\lecture}[6]{%
%   \begin{document}  <-- why ?
  \thispagestyle{plain}
  \global \def \lecturenum {#1}
  \global \def \lecturetitle {#2}
  \global \def \lecturescribe {#3}
  \global \def \lecturedate {#4}
  \global \def \lecturer {#5}
  \global \def \course {#6}
  \handout
}


\newcommand{\theend}{\end{document}}% <-- why?
\end{filecontents*}
% --------------------------------------------------------------------

\usepackage{lecturenotes}
\usepackage{lipsum}

\begin{document}

\lecture{01}{Sample Lecture Notes}{John Sam}{01/01/2000}{Mark
    John}{PHYSICS 124: Physics of Energy}

\lipsum[1]
\newpage
\lipsum[1-10]

\theend % <-- why?
\end{document}
Related Question