3

I have several chapters in a book. I want a fancy header above the first chapter, so on this page the chapter number and title should be typeset a little lower than usual (below the header). All subsequent pages and chapter titles should be typeset normally.

\documentclass[11pt]{book}

\usepackage{lipsum}
\usepackage{fancyhdr}
\fancypagestyle{firstpage}{
  \fancyhf{}
  \fancyhead{
    \begin{minipage}{\textwidth}
      {\sffamily Some information\\More information\\Another note\\This is a rather lengthy header\\foo\\bar\\buz\\blah\\beep}
    \end{minipage}
  }
}

\begin{document}

\chapter{A first chapter}
\thispagestyle{firstpage}

This is the first chapter. This page should include a fancy header
with some information, and as such the chapter number and title should
appear a little lower than for other chapters.

\lipsum[1-12]

\chapter{A second chapter}

This is the second chapter. It should be formatted normally, i.e., the
chapter number and title should appear at the top of the page, since
there is no special header here

\lipsum[13-19]

\end{document}

There are two problems:

  1. The first chapter is not typeset low enough. It overlaps with the header.
  2. All subsequent pages are typeset much lower. The bottom margin is almost 0, and the top margin is huge.

LaTeX outputs a warning too:

Package Fancyhdr Warning: \headheight is too small (12.0pt): 
 Make it at least 133.13336pt.
 We now make it that large for the rest of the document.
 This may cause the page layout to be inconsistent, however.

This seems to be the problem, but I don't understand how to fix it. If I put

\setlength{\headheight}{134pt}

inside the \fancypagestyle{firstpage}{...} declaration, then the first chapter title is typeset lower, and all subsequent pages look fine. This is close to what I want. However, the bottom margin of the first page is still almost 0, and so the text at the end of the first page goes all the way to the bottom. How to fix this last problem?

This does not appear to be a duplicate. There are two related questions:

However, in those cases setting \headheight seems to solve it, and they do not appear to experience my latter problem.

2

The trick is to set the minipage to have zero height, so it won't influence the head height for the subsequent pages (at the eyes of fancyhdr). This requires that the rule is typeset in the minipage, rather than printing the usual head rule that would appear in the wrong position.

I also adjusted the space above chapter titles; the easiest way is with etoolbox: instead of 50pt (here 50\p@) I set 80pt, adjust to suit. The first patch to \chapter is meant to avoid the need for \thispagestyle{firstpage} in the document.

Setting the head height to 13.6pt is required by the fact you use 11pt size.

\documentclass[11pt]{book}

\usepackage{etoolbox}
\usepackage{fancyhdr}

\usepackage{lipsum} % just for the example

\setlength{\headheight}{13.6pt}
\fancypagestyle{firstpage}{%
  \renewcommand{\headrulewidth}{0pt}%
  \fancyhf{}%
  \fancyhead{%
    \begin{minipage}[t][0pt]{\textwidth}
    \sffamily
    Some information\\
    More information\\
    Another note\\
    This is a rather lengthy header\\
    foo\\
    bar\\
    buz\\
    blah\\
    beep\strut
    \hrule
    \end{minipage}% <--- don't forget
  }%
}

\patchcmd{\chapter}{plain}{firstpage}{}{} % avoid the need of \thispagestyle after \chapter
\makeatletter
\patchcmd{\@makechapterhead}{50\p@}{80\p@}{}{}  % chapter head is lower
\patchcmd{\@makeschapterhead}{50\p@}{80\p@}{}{} % starred chapter head is lower
\makeatother

\begin{document}

\chapter{A first chapter}

This is the first chapter. This page should include a fancy header
with some information, and as such the chapter number and title should
appear a little lower than for other chapters.

\lipsum[1-12]

\chapter{A second chapter}

This is the second chapter. It should be formatted normally, i.e., the
chapter number and title should appear at the top of the page, since
there is no special header here

\lipsum[13-19]

\end{document}

enter image description here

  • Many thanks, this fixes it! One question: why did you use \patchcmd{\chapter}{plain}{firstpage}{}{}? If I understand correctly, this will cause all my chapter titles to have a fancy header, but I only wanted this for the first chapter. This is already achieved by putting \thispagestyle{firstpage} below the first \chapter. If I remove the \patchcmd{\chapter}{plain}{firstpage}{}{} I get exactly what I wanted. :-) – Malte Skoruppa Oct 21 '14 at 21:24
  • 1
    @MalteSkoruppa I forgot to remove \thispagestyle after \chapter; the patch is intended to do precisely that. – egreg Oct 21 '14 at 21:24
  • Thanks, that's what I assumed. Since I only need a header for the first chapter I'll use \thispagestyle, but your solution additionally shows an elegant way to do this for all chapters. :-) – Malte Skoruppa Oct 21 '14 at 21:28
  • @egreg this works for book class, but in memoir class not works, what are the changes to be made to work in the memoir class? – juanuni May 24 '15 at 18:15
  • @juanuni One should not use fancyhdr with memoir, which uses a different method for setting header and footer. – egreg May 24 '15 at 19:11

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.