1

Problem

How can I write a document class to place page numbers one inch from the bottom on pages with a chapter heading and place the text body one inch from the bottom on pages without a chapter heading (with page numbers in the header instead)?

Details

I'm voluntarily creating a thesis class for my university so that future students don't have to worry about the formatting and layout of their theses if they choose to write them in LaTeX. The university thesis guide requires that if a page includes a chapter heading then the page number should be 1 inch from the bottom of the page but if a page does not contain a chapter heading then the page number should appear as specified by the appropriate style guide.

So far this is easily implemented by using the geometry package with the appropriate margins and the includeheadfoot option (like in this question) and then specifying an appropriate default pagestyle (since pages with chapter headings will override with plain pagestyle as desired).

The catch is that the thesis guide also requires that if a page number is not on the bottom then the text body must be 1 inch from the bottom of the paper instead. Since all the style guides (APA, MLA, Chicago/Turabian, etc.) suggest putting page numbers in the header, for me this means a page number is in the footer if and only if the page has a chapter heading.

Perhaps if I could somehow modify the geometry of pages that have chapter headings to use the includefoot option while other pages default to a geometry without that option, I could solve my problem. The accepted answer to this question about changing geometry for a single page gave me the idea to patch \chapter with \pretocmd like so:

\pretocmd{\chapter}{\newgeometry{margin=1in,includeheadfoot}}{}{}

The only issue with this approach is I don't know how to restore geometry on subsequent pages of a chapter, especially since I won't know the contents of chapters.

MWE

\documentclass[letterpaper,12pt]{report}
\usepackage[margin=1in,includehead,includefoot,showframe]{geometry}
\usepackage{lipsum}

\pagestyle{myheadings}

% Remove includefoot option above and uncomment lines below to see patch attempt.
% \usepackage{etoolbox}
% \pretocmd{\chapter}{\newgeometry{margin=1in,includeheadfoot}}{}{}

\begin{document}
\chapter{Test}
Page number on this page should be in the footer and 1in from the bottom of the page.  Page number on the next page should be in the header and 1in from the top of the page and last line of text on the next page should be 1in from the bottom of the page.\par
\lipsum[1-10]
\end{document}
  • May be I am wrong but when I have tried \pretocmd{\chapter}{\newgeometry{margin=1in,includeheadfoot}}{}{} I noticed that there is no need to add anything else to restore the old geometry for subsequent pages. – Hafid Boukhoulda May 17 at 16:52
  • @HafidBoukhoulda Forgive me, but I don't get this behavior? If I use the MWE as-is or if I remove the includefoot option from the \usepackage[...]{geometry} line and then uncomment the patch, all pages in the MWE behave as if includefoot is enabled. Only the page with the chapter heading should behave as if includefoot is enabled while all the remaining pages should behave as if it wasn't. – FringePioneer May 17 at 21:07
0

To accomplish what you described, the first step is to use the geometry package to implement a default page layout with only a header (using includehead).

The plain page style (having a footer instead of a header) could then adjust the \topmargin value for just the one page in which the chapter heading is located; in effect, moving the header with no text into the top margin while also bringing the footer above the bottom 1" margin.

To implement this approach, try the following (based on your working example):

\documentclass[letterpaper,12pt]{report}

% Define default page layout with 1" margins and header only
\usepackage[margin=1in,includehead,showframe]{geometry}

\usepackage{lipsum}

\pagestyle{myheadings}

% Set \headsep so that \headsep + \headheight is the same length as \footskip
\setlength\headsep{\footskip}
\addtolength\headsep{-\headheight}

% Plain page style adjusted with the footer above bottom margin
\usepackage{etoolbox}
\makeatletter
    \appto{\ps@plain}{%
        \addtolength\topmargin{-\footskip}}
\makeatother

\begin{document}
\chapter{Test}
Page number on this page should be in the footer and 1in from the bottom of the page.  Page number on the next page should be in the header and 1in from the top of the page and last line of text on the next page should be 1in from the bottom of the page.\par
\lipsum[1-10]
\end{document}

Note: Using this approach, the geometry package's showframe option does not properly render on pages that use the plain page style.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.