(Not a dupe of Is something the first item on a page? and another similar question, because these involve preventing rules at the top of a page by putting them in leaders; but leaders require boxes, and I don't want a box, but simply to issue a header command.)

So I often roll my own sectioning commands, and I'm currently typesetting a volume which has frequent, shorter chapters. As a result, I don't want to start a new page for every chapter, so when I wrote my sectioning command, it simply skips, prints the title, sends the title to the TOC, then skips again to be ready for the text. Normally, these chapters do not begin at the start of a page; so in that case, having the full, normal header is the correct behavior.

Occasionally, however, the chapters do begin at the top of a page, and in those circumstances I'd like to have the equivalent of \thispagestyle{plain} happen. I can't simply put that in the chapter definition, because most of the time the chapters don't start at the top of the page. I only want a plain pagestyle when the chapter falls at the top of the page. MWE:

    \vskip 3em plus1em minus0.5em%
    \hbox to\linewidth{\LARGE\hfil#1\hfil}%
    \vskip 3em plus1em minus0.5em%
\newchap{New Chapter Here}

Notice that, although the chapter is the first thing on the page, we end up with the full header. (As the code directs.) I'd like to know something I can put in \newchap which, when it's at the top of the page, will issue \thispagestyle{plain}, or something with equivalent functionality.


The following is not thoroughly tested, but should suffice with some tweaking.

The idea is to update \newchap to include some code from needspace. This allows you to force a new page based on the amount of space available on the page, and condition accordingly between issuing \thispagestyle{plain} and \thispagestyle{fancy}:

enter image description here

\usepackage{lipsum}% Just for this example

\topchaptrue% You'll start with a chapter at the top

% http://tex.stackexchange.com/a/32622/5764
% \needspace{<len>}{<NOT enough space>}{<enough space>}
\newcommand{\needspace}[3]{\par \penalty-100\begingroup
  \dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
  \ifdim \dimen@>\dimen@ii% execute the following if there IS NOT enough space on page
    \ifdim \dimen@ii>\z@
    #2% <NOT enough space>
  \else% execute the following if there IS enough space on page
    #3% <enough space>


  \needspace{6em}{% <not enough space>
  }{% <enough space>
  \vspace{3em plus 1em minus 0.5em}
  \noindent\makebox[\linewidth]{\LARGE #1}%
  \par\nobreak\vspace{3em plus 1em minus 0.5em}

\sloppy% Just for this example

\newchap{New chapter}

\newchap{Another chapter}

\newchap{Yet another chapter}

\newchap{Penultimate chapter}

\newchap{Final chapter}


The choice for a required space of 6em for the heading is based on an estimate of the header size (vertical space included). This may require some adjustment from your end to ensure proper page-breaking.

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.