Is there a way to count the number of equations (or other counted items) in a page and display it in the header? I am having trouble with keeping correct count when the page breaks and I'm not using \newpage
. Actually, \thepage
also is broken and displaying the wrong page number when it's in the body of the document.
I'm currently working on the following document:
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{everypage}
\pagestyle{fancy}
\newcounter{CurrentPageCounter}
\newcounter{CurrentEquation}[CurrentPageCounter]
\lhead{Page \theCurrentPageCounter{}, equations on page: \theCurrentEquation{}} % not working
\newcommand{\addequation}{\stepcounter{CurrentEquation}}
\AddEverypageHook{\stepcounter{CurrentPageCounter}}
\chead{\today}
\rhead{Page \thepage{} of \pageref{LastPage}}
\cfoot{}
\begin{document}
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:
\[ 1 != 0 \]
\\
\vspace{50em}
\\
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:
\[ 1 = 1 \]
\newpage
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:
\[ a > 0 \]
\end{document}
On an updated system, this gives output like
Page 0, equations on page: 2 March 31, 2021 Page 1 of 3
Equation 1 on page 1:
1! = 0
Page 1, equations on page: 0 March 31, 2021 Page 2 of 3
Equation 2 on page 1:
1=1
Page 2, equations on page: 1 March 31, 2021 Page 3 of 3
Equation 1 on page 3:
a>0
but it should have "equations on page: 2" for the first page and "equations on page: 1" for the second.
Update: With Willie's changes I have the following issue where the header reports the incorrect count:
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{perpage}
\pagestyle{fancy}
\newcounter{CurrentEquation}
\MakePerPage{CurrentEquation}
\lhead{Page \thepage{}, equations on page: \theCurrentEquation{}} % not working, appears to update after the third equation
\newcommand{\addequation}{\stepcounter{CurrentEquation}}
\chead{\today}
\rhead{Page \thepage{} of \pageref{LastPage}}
\cfoot{}
\begin{document}
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 != 0 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ 1 = 1 \]
\newpage
Equation \addequation{}\theCurrentEquation{} on page \thepage{}:\[ a > 0 \]
\end{document}
The output looks something like
Page 1, equations on page: 3 March 31, 2021 Page 1 of 3
Equation 1 on page 1:
1! = 0
Equation 2 on page 1:
1=1
Equation 3 on page 1:
1=1
Equation 4 on page 1:
1=1
Equation 5 on page 1:
1=1
Equation 6 on page 1:
1=1
Equation 7 on page 1:
1=1
Equation 8 on page 1:
1=1
Equation 9 on page 1:
1=1
Equation 10 on page 1:
1=1
Equation 11 on page 1:
1=1
Equation 12 on page 1:
1=1
Equation 13 on page 1:
1=1
Equation 14 on page 1:
1=1
Equation 15 on page 1:
1=1
Equation 16 on page 1:
1=1
Equation 17 on page 1:
1=1
Equation 18 on page 1:
1=1
Page 2, equations on page: 5 March 31, 2021 Page 2 of 3
Equation 1 on page 1:
1=1
Equation 2 on page 1:
1=1
Equation 3 on page 1:
1=1
Equation 4 on page 2:
1=1
Equation 5 on page 2:
1=1
Page 3, equations on page: 1 March 31, 2021 Page 3 of 3
Equation 1 on page 3:
a>0
CurrentPageCounter
and just using\thepage
, which is already provided by LaTeX.everypage 2020/10/17 R2.0b
Package: everypage 2007/06/20 1.1 Hooks to run on every page
in it.