1

I'm using the command \pagestype{myheadings} to make sure that the page header contains nothing else that the page number.

However, I can't manage to make the page number of the first page of chapter to be displayed up in the page corner.

Here is a sample code of what I'm doing so far:

\documentclass[12pt,a4paper]{book}

\usepackage[T1]{fontenc} \usepackage[french]{babel}

\pagestyle{myheadings}

\title{Test book} \author{Someone} \date{\today}

\usepackage{lipsum}

\begin{document} \sloppy \maketitle

\chapter{First chapter}
\lipsum[1-100]

\backmatter
\tableofcontents

\end{document}

Example image of the problem

Best rgards!

Mensch
  • 65,388
  • 2
    Welcome to TeX.SE. I appreciate that you gave a bit of sample code. For future questions, it would help if you gave a complete sample code. For this one, you've not shown us how you define myheadings, and not shown what package you're using to help you do that. – Teepeemm Jan 15 '21 at 14:50
  • Do you want the page number to be in the corner for all pages, or just the first page of the chapter? Have you considered using the KOMA-Script class scrbook? – likethevegetable Jan 15 '21 at 16:15

1 Answers1

1

The book class uses the plain page style for the first page of the chapter. Here is the definition in book.cls:

\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
     ----------->>  \thispagestyle{plain}%    <<-----------
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@chapter\@schapter}

There are at least two ways to change this.

Using the fancyhdr package and redefining the plain style (see pages 12-13 of the documentation).

\usepackage{fancyhdr}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyhead[LE,RO]{\thepage}%
  \renewcommand{\headrulewidth}{0pt}%
  \renewcommand{\footrulewidth}{0pt}%
  }

Via etoolbox:

\usepackage{etoolbox}
\patchcmd{\chapter}{plain}{myheadings}{}{}

In fact this is equivalent to

\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                    \thispagestyle{myheadings}%
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@chapter\@schapter}
\makeatother
Ivan
  • 4,368