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.

How can I increase my counter with every new page and reset to 0 again when it comes to a new chapter?

I know that I can link my counter to a chapter so that it can be reset on every new chapter by:

\newcounter{counter1}[chapter]

but then I have no idea how to increase it.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

Using everyshi you can increment the counter at every page shipout:

\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\newcounter{pagecntr}[chapter]% New counter pagecntr is reset with an increment in chapter
\EveryShipout{\stepcounter{pagecntr}}% Step pagecntr every page

This resets pagecntr to 0 on the first page of every chapter. atbegshi could provide similar functionality.

share|improve this answer
add comment

One could also do it manually in the way shown in this example.

\documentclass{article}
\parindent 0ex
\begin{document}
\newcounter{chapoffset}
\newcounter{chappage}
\setcounter{chapoffset}{0}
\setcounter{chappage}{0}
\newcommand{\newchap}{NEWCHAPTER\\\setcounter{chapoffset}{\thepage}%
  \addtocounter{chapoffset}{-1}}
\newcommand\mychappage{\setcounter{chappage}{\value{page}}%
\addtocounter{chappage}{-\value{chapoffset}}\thechappage}

                                       \newchap
Page \thepage\\
Chapter page \mychappage \clearpage
Page \thepage\\
Chapter page \mychappage \clearpage    \newchap
Page \thepage\\
Chapter page \mychappage \clearpage

\end{document}
share|improve this answer
add comment

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.