4

I am trying to prepare a package for students that offers a uniform standard title page for their work (homework, reports, theses, and probably more).

I have the title page laid out as it should be. However, I am having problems setting the margins. I wish to centre ONLY the title page, without side effects to possible margin settings that the students might have already set up for the rest of their document.

I have seen other solutions such as this one, but they invariably make use of some package like geometry etc. I am seeking a solution that works with plain LaTeX only. The reason is that I do not know what class the title page package ends up in (book, report, memoir, classicthesis, ...), and I need something that provides maximum compatibility.

  • Are they using pdfLaTeX? If so, just create a separate class to produce just the title page and have them use the pdfpages package to include it. Nothing you do is going to be compatible inline with absolutely anything they might be using. – cfr Sep 07 '15 at 21:26
  • I don't know what they are using. And I have thought about the pdfpages solution, as this is what I do for my own thesis title page. But for someone maybe new to TeX, and more importantly maybe already struggling to get the required work done, a two-step process is far worse than accepting small incompatibilities with e.g. the geometry package. And since geometry does it, it should be doable, right? –  Sep 07 '15 at 21:34
  • It is going to break somebody's document. Bound to. What do you mean by plain LaTeX exactly? Note that classes and packages do not just add things, they change things. So, by \begin{document}, \macroA may not do the same thing in student 1's document as it does in student 2's. I'm no guru but everything I know suggests that you simply can't do this in a way which will be compatible with every student's work: not if they could be using literally any combination of class and packages. Not using a package doesn't mean compatible with everything. Packages are just code. Code changes stuff. – cfr Sep 07 '15 at 21:51
  • Of course people might load packages and break stuff. I merely wish to minimise the way in which my code does likewise. The question is simply how to achieve in a standalone way what the \newgeometry, \restoregeometry, ... commands from geometry do. –  Sep 07 '15 at 22:08

1 Answers1

1

One option would be to borrow the definitions for the \changepage command from the changepage package:

\documentclass{article}
\usepackage{lipsum}

\makeatletter
% Definitions taken from changepage.sty
\begingroup
\catcode`\Q=3
\long\gdef\@ifmtarg#1{\@xifmtarg#1QQ\@secondoftwo\@firstoftwo\@nil}
\long\gdef\@xifmtarg#1#2Q#3#4#5\@nil{#4}
\endgroup

% Set the page output parameters
\DeclareRobustCommand{\ch@ngetext}{%
  \setlength{\@colht}{\textheight}\setlength{\@colroom}{\textheight}%
  \setlength{\vsize}{\textheight}\setlength{\columnwidth}{\textwidth}%
  \if@twocolumn%
    \advance\columnwidth-\columnsep \divide\columnwidth\tw@%
    \@firstcolumntrue%
  \fi%
  \setlength{\hsize}{\columnwidth}%
  \setlength{\linewidth}{\hsize}}

\DeclareRobustCommand{\changepage}[9]{%
  \@ifmtarg{#1}{}{\addtolength{\textheight}{#1}}%
  \@ifmtarg{#2}{}{\addtolength{\textwidth}{#2}}%
  \@ifmtarg{#3}{}{\addtolength{\evensidemargin}{#3}}%
  \@ifmtarg{#4}{}{\addtolength{\oddsidemargin}{#4}}%
  \@ifmtarg{#5}{}{\addtolength{\columnsep}{#5}}%
  \ch@ngetext%
  \@ifmtarg{#6}{}{\addtolength{\topmargin}{#6}}%
  \@ifmtarg{#7}{}{\addtolength{\headheight}{#7}}%
  \@ifmtarg{#8}{}{\addtolength{\headsep}{#8}}%
  \@ifmtarg{#9}{}{\addtolength{\footskip}{#9}}}
\makeatother
%
%\changepage{<textheight>}{<textwidth>}{<even-side-margin>}{<odd-side-margin>}{<columnsep>}{<topmargin>}{<headheight>}{<headsep>}{<footskip>}  

\begin{document}

\changepage{7cm}{6cm}{-3cm}{-3cm}{}{-3cm}{}{}{}
\lipsum[1-10]
\clearpage
\changepage{-7cm}{-6cm}{3cm}{3cm}{}{3cm}{}{}{}
\lipsum[1-5]
\end{document}

The result:

enter image description here

Gonzalo Medina
  • 505,128
  • This works very well, thank you. I have renamed the command to something unique for the package, in case someone uses changepage. –  Sep 07 '15 at 22:48
  • @nes I thought you wanted a standard title page? This gives a different result for memoir than it does for report, and a different result again for book. – cfr Sep 08 '15 at 01:29
  • @nes Try \documentclass{book}, \documentclass{book}\usepackage{geometry}, \documentclass{memoir}. (Restricting to classes which default to double-sided.) Or \documentclass{report}. (For one which doesn't.) – cfr Sep 08 '15 at 01:36
  • @cfr Thanks for your concern, I take one/twoside and one/twocolumn into account when laying out the title. I really only needed a means to change the geometry for a single page. –  Sep 08 '15 at 08:26