Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to use both regular page numbering (as in 1, 2, 3, etc) and n-m page numbering (1-1, 1-2, 2-1, 2-2, etc) in a document I'm preparing.

This far I've been playing around with custom counters but the obvious answer, using \addtocounter to subtract the page where the current chapter started from \thepage defeats that purpose because I still want regular page numbers.

I can't really post an MWE because it's something I don't really know how to do. On the "pseudo-MWE" below \nmpage is a hypothetic command that outputs the page number in the format <chapter>-<page_of_chapter>, so the 5th page of chapter 2 would be 2-5.

Any ideas on how I could achieve that?

\documentclass[12pt,a4paper,openany]{book}
\usepackage{fancyhdr}  
  \pagestyle{fancy}  
  \renewcommand{\chaptermark}[1]{%  
    \markboth{#1}{}}  
  \renewcommand{\sectionmark}[1]{%  
    \markright{\thesection #1}}  
  \fancyhf{}  
  \fancyhead[LE,RO]{\thepage}%   
  \fancyhead[LO]{\rightmark}%  
  \fancyhead[RE]{\leftmark}%  
  \fancyfoot[LE,RO]{\nmpage}%  

\begin{document}

\chapter{Chapter 1}

Onononononon

\chapter{Chapter 2}

Yada yada yada.

\end{document}
share|improve this question
    
Which is the main page number, especially which is used for references (\pageref)? –  Heiko Oberdiek Nov 30 '12 at 21:38
    
It's \thepage, which I intentionally leave untouched. –  Francisco Nov 30 '12 at 21:43

2 Answers 2

up vote 4 down vote accepted

The main page number is \thepage with regular (arabic) numbering. This is also used for page references. Thus we do not need to do anything here.

Additionally the footer should show a page number of the form \thechapter-<arabic page relative to the chapter>. All we need is the page number of the chapter start. Since \chaptermark is already redefined, the definition for \StartChapterPage is put there. A chapter starts a new page, thus we can use \value{page} without resorting to the referencing system. Second advantage of \chaptermark is that it is not called for unnumbered chapters. In order to skip the first pages, \nmpage is defined empty and \printnmpage is defined to do the real work. At the first numbered chapter \nmpage gets the meaning of \printnmpage and the composite page number is shown:

The following definitions are added to the MWE of the question:

\newcommand*{\StartChapterPage}{1}
\newcommand*{\nmpage}{}
\newcommand*{\printnmpage}{%
  \thechapter-\the\numexpr\value{page}-\StartChapterPage+1\relax
}

And the definition for \chaptermark changes as follows:

\renewcommand{\chaptermark}[1]{%
  \xdef\StartChapterPage{\the\value{page}}%
  \global\let\nmpage\printnmpage
  \markboth{#1}{}}
share|improve this answer
    
Wow. Just... wow. I may have learned more about LaTeX in the past minute than in the last week. Thank you, Heiko. –  Francisco Nov 30 '12 at 22:26

That can be achieved by creating a new counter that is reset with each chapter, then incrementing it everytime it is used in the headings:

\documentclass{book}

\newcounter{nmpage}[chapter]

\usepackage{fancyhdr}
\pagestyle{fancy}
\lfoot{}
\cfoot{\thechapter--\addtocounter{nmpage}{1}\thenmpage}
\usepackage{lipsum}
\begin{document}
\chapter{The beginning}
\thispagestyle{fancy}

\lipsum[1-6]


\chapter{More Material}
\thispagestyle{fancy}

\lipsum[7-8]
\end{document}

Maybe looking at the memoir class might be a better place. I was using the book class.

share|improve this answer
    
The \fancypagestyle{plain}{...} trick is described in the manual of fancyhdr –  egreg Nov 30 '12 at 20:41
    
My problem is not with fancyhdr - what I need is the page number in the footer to be reset everytime a new chapter begins, to the first page of chapter 2 would be 2-1, not 2-3. –  Francisco Nov 30 '12 at 20:46
1  
You could order the page counter to reset. But I wouldn't touch it and rather create a new counter which is reseted every chapter. I don't remember how to do it at this moment, but if no one answers I will look around. –  Manuel Nov 30 '12 at 20:53
    
\newcounter{nmpage}[chapter] would do just that. The catch is how to increment it every time page is incremented. –  Francisco Nov 30 '12 at 21:10
2  
In the code of @A.Ellet instead of \cfoot{\thechapter--\thepage} you should use \cfoot{\thechapter--\addtocounter{nmpage}{1}\thenmpage}. I think it works. But you should redefine some more commands if you want \pageref and similar to work. I hope someone answers. –  Manuel Nov 30 '12 at 21:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.