[Tex/LaTex] Two types of page number in each page

header-footerpage-numbering

In a report, I would like to place a page number at the bottom, running 1, 2, 3,… as is usually the case with a document: 1 for the 1st page; 2 for the 2nd page, …
However, in each Chapter of this document, I would like to put another page number at the top. For example, in Chapter II, 2-1 at top right on the 1st page of Chapter II and 47 at the bottom if Chapter II begins in the 47th page from the beginning, 2-2 at top left on the 2nd page of Chapter II and 48 at the bottom, and so forth.

Please tell me a set of proper TEX commands for this 2 different types of page numbers for each page.

Best Answer

Since the first page of a chapter is handled differently than others, and is actually typeset using the plain page style via

\thispagestyle{plain}

at a call to \chapter, one can modify the plain page style and additionally use fancyhdr to create a separate page style (fancy) for the rest of the non-first-chapter-pages.

enter image description here

\documentclass{book}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newcounter{chappage}[chapter]% chappage is slave to chapter
\renewcommand{\thechappage}{\stepcounter{chappage}\arabic{chappage}}

\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\fancypagestyle{plain}{% 'plain' page style (used for first page of chapter)
  \fancyhf{}% clear all header and footer fields
  \renewcommand{\headrulewidth}{0pt}% no header rule
  \renewcommand{\footrulewidth}{0.4pt}% footer rule
  \fancyhead[LE,RO]{\thechapter-\thechappage}% 
  \fancyfoot[C]{\thepage}
}
% Regular 'fancy' page style
\fancyhf{}% clear all header and footer fields
\fancyhead[LE,RO]{\thechapter-\thechappage}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}% header rule
\renewcommand{\footrulewidth}{0.4pt}% footer rule
\pagestyle{fancy}% Set page style to 'fancy'

\begin{document}
\chapter{First chapter}\lipsum[1-15]
\chapter{Second chapter}\lipsum[1-15]
\chapter{Third chapter}\lipsum[1-15]
\chapter{Last chapter}\lipsum[1-15]
\end{document}

Note that I've added a footer rule on the first chapter page, which can be removed. Also, no marks are added to the inner pages of the chapters, but this can also be added. Since there was no requirement in the original post, it's been kept simple here.

The advantage with this approach is that you are able to modify what you want displayed in the header/footer on the first chapter page separately from that of the other pages, since the chapter first page is usually typeset differently and may require a different look.

Note that modification of the plain page style will also impact how all the other \chapter-like first pages look. For example, \tableofcontents, which typesets as a \chapter* by default, will also have this. If this is unwanted, a little more work is required.