[Tex/LaTex] How to detect if abstract reaches a second page, in order to add a header

abstractheader-footerpage-numberingthesis

I'm writing a thesis for which the very first page (or 2 if it's long enough) is the abstract. I have two formatting requirements that I can't figure out, when the abstract continues onto the second page:

  1. how do I prevent the page number from showing up on page 2? I can suppress it on page 1 with \thispagestyle{empty}, but I don't know how to do that for page 2 since I don't know where page 2 starts
  2. how do I add a header that only applies to page 2? Again, I don't know where to put this header declaration since I don't know where page 2 starts

Here are the actual instructions:

If the abstract extends onto a second page, that page should be headed as follows:

Jane Mary Doe – [University], [year of graduation] 

The abstract is not paginated.

If the abstract fits on 1 page, then there shouldn't be a second abstract page. Can anybody help me understand this problem?

Best Answer

Since there is no example to work on here, this answer involves some guesswork, and is indebted to the suggestion from @cfr in the comments. I've included some comments in the code to explain it a bit. The crucial (and rather clever) idea given by @cfr is to turn on a special page style for the abstract, but suppress it on the first page only.

\documentclass{article}
\usepackage{lipsum}
% define a new page style
\makeatletter
\newcommand{\ps@abstract}{%
    \renewcommand{\@oddhead}{\hss Jane Mary Doe -- University of Oxford, 1264\hss}%
    \renewcommand{\@evenhead}{\@oddhead}% left same as right
    \renewcommand{\@oddfoot}{}% blank footers
    \renewcommand{\@evenfoot}{}}
\makeatother
\begin{document}
\pagestyle{abstract} % turn on the new page style
\thispagestyle{empty} % but turn it off for the first page
\begin{abstract}
    Here goeth a pithy summary of the wonderful text herein.
    \lipsum % add some dummy text to push us over 1 page
    % the new heading will appear on p2 of the abstract
\end{abstract}
\clearpage  % or \cleardoublepage if you are in two sided mode
\pagenumbering{arabic} % reset page numbers to 1 (only if you want to)
\pagestyle{plain} % or whatever style you want for the rest of the doc
\section{Introduction}

Here goeth the rest of the booke.

\end{document}

Explanations

Page styles in LaTeX are defined and switched on in two stages: to define a style abc, you define a new command \ps@abc that re-defines the four header & footer commands shown above. You then switch to that style using \pagestyle{abc}. If you want a page style to apply the current page only, then you can use \thispagestyle{abc}; the previous page style will resume on the following pages.

The standard styles are empty, plain (the default in article class), headings, and myheadings. The page layout section on Wikibooks has some useful reference material. There are several packages available that simplify and extend these basic LaTeX mechanisms. You might like to try fancyhdr for example.

Page styles are applied when TeX gets to the end of a page, so if you switch headings half-way through a page the new style applies to the current page not the next one. So it's usually a good idea to make sure that you have started a new page, before you switch heading styles. The \clearpage command does that for you (and also ensures that any pending floats, such as figure or table environments, are placed before the new page starts).

Related Question