# Two types of page number in each page

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.

-
The page style of the first page differs from that of non-first pages. If seems like you're after the same style across all pages. For example, do you want a header rule across the first page as well? I'm assuming you do not. –  Werner Dec 26 '11 at 1:14

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.

\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{\footrulewidth}{0.4pt}% footer rule
\fancyfoot[C]{\thepage}
}
% Regular 'fancy' page style
\fancyhf{}% clear all header and footer fields
\fancyfoot[C]{\thepage}
\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.

-
But note that this gives weird numbering if you don't change the plain pagestyle. –  rdhs Dec 26 '11 at 1:51
@rdhs: By changing the plain page style, all chapters will use it since they all issue \thispagestyle{plain}. If you use a different, newly created page style (say chapter), then a little patching is require; as I mention, "a little more work is required." –  Werner Dec 26 '11 at 1:54

With \newcounter{...}[chapter] you can define a counter which resets to 0 with each new chapter. Since you probably want the first page to logically be 1, I add 1 to the counter when it gets displayed. Using fancyhdr to show both nubers at once:

\documentclass{book}

\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\newcounter{pagei}[chapter]
\number\numexpr\value{pagei}+1\relax}
\fancyfoot[C]{\thepage}

\begin{document}
\chapter{Chapter One}
\lipsum[1-20]
\chapter{Chapter Two}
\lipsum[1-20]
\end{document}

If you want to suppress the new headers on empty pages, look into emptypage.

-
This does not show the new page numbering on the first page of the chapter though. For that you have to manually add \thispagestyle{fancy} after \chapter{..}, or set it automatically using, for example, etoolbox. –  Werner Dec 26 '11 at 1:13
@Werner How would you do that using etoolbox? I tried \apptocmd{\chapter}{\thispagestyle{fancy}}{}{} and it gave an error: Argument of \thispagestyle has an extra }. –  rdhs Dec 26 '11 at 1:19
\chapter in book issues \thispagestyle{plain}. You could just use \usepackage{etoolbox}\patchcmd{\chapter}{plain}{fancy}{}{}. However, since you modify pagei within the header, you'll notice that your first page now becomes X-2 for which you have to correct. –  Werner Dec 26 '11 at 1:25