0

I have to add the theorem numbers to the footer using the fancyhdr package. It works fine, if I only add the last theorem number that is mentioned on that page (see example below). However, I would like to add the numbers of **all* theorems that are mentioned on a specific page. Thus, in the example below, I need the footer on page 1 to be

Theorem 1, 2

instead of

Theorem 2

and on page 2, I need the footer to be

Theorem 2, 3

instead of

Theorem 3.

Is there a solution how this can be solved?

Here is the example code:

\documentclass{article}

\usepackage{fancyhdr}
\usepackage{amsthm}

\newtheorem{Theorem}{Theorem}

\textheight7cm

\begin{document}


\pagestyle{fancy}
\fancyfoot[C]{Theorem \theTheorem}


\begin{Theorem}
  This is the first theorem on page 1.
\end{Theorem}

\begin{Theorem}
  This is the second theorem on page 1.
\end{Theorem}
Here comes a proof of the second theorem which is continued on page 2. \\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.

\begin{Theorem}
  This is the third theorem, which starts on page 2.
\end{Theorem}
\end{document}
0

1 Answer 1

1

You can use xpatch to automatically add \addtheorem to the Theorem environment.

\documentclass{article}
\textheight7cm % MWE only, I assume
\usepackage{fancyhdr}
\usepackage{amsthm}

\newtheorem{Theorem}{Theorem}

\newcommand*{\theoremname}{Theorem}% used in \ifx
\newcommand*{\theoremlist}{Theorem}% reserve global name

\newcommand{\addtheorem}{\ifx\theoremname\theoremlist\relax
  \xdef\theoremlist{\theoremname~\theTheorem}%
\else
  \xdef\theoremlist{\theoremlist, \theTheorem}%
\fi}

\makeatletter
\fancyfoot[C]{\ifx\theoremname\theoremlist \else
  \theoremlist
  \global\let\theoremlist=\theoremname
\fi
\ifx\@currenvir\theoremname\relax
  \xdef\theoremlist{\theoremname~\theTheorem}%
\fi}
\makeatother

\begin{document}

\pagestyle{fancy}

\begin{Theorem}\addtheorem
  This is the first theorem on page 1.
\end{Theorem}

\begin{Theorem}\addtheorem
  This is the second theorem on page 1.\\
    Since this theorem is rather long, it is continued on page 2. \\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
    Text of this theorem.\\
\end{Theorem}

\end{document}

This version allows (requires) you to arbitrarily set the end of the theorem using \Theoremfalse.

\documentclass{article}
\textheight7cm % MWE only, I assume
\usepackage{fancyhdr}
\usepackage{amsthm}

\newtheorem{Theorem}{Theorem}

\newcommand*{\theoremname}{Theorem}% used in \ifx
\newcommand*{\theoremlist}{Theorem}% reserve global name
\newif\ifTheorem

\newcommand{\addtheorem}{\ifx\theoremname\theoremlist\relax
  \xdef\theoremlist{\theoremname~\theTheorem}%
\else
  \xdef\theoremlist{\theoremlist, \theTheorem}%
\fi
\global\Theoremtrue}

\fancyfoot[C]{\ifx\theoremname\theoremlist \else
  \theoremlist
  \global\let\theoremlist=\theoremname
\fi
\ifTheorem
  \xdef\theoremlist{\theoremname~\theTheorem}%
\fi}

\begin{document}

\pagestyle{fancy}

\begin{Theorem}\addtheorem
  This is the first theorem on page 1.
\end{Theorem}\Theoremfalse

\begin{Theorem}\addtheorem
  This is the second theorem on page 1.
\end{Theorem}
Here comes a proof of the second theorem which is continued on page 2. \\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.
\par\Theoremfalse

\begin{Theorem}\addtheorem
  This is the third theorem, which starts on page 2.
\end{Theorem}\Theoremfalse
\end{document}

This version uses a counter (firstthm) to keep track of the first theorem on a page (or 0 if none).

\documentclass{article}
\textheight7cm % MWE only, I assume
\usepackage{fancyhdr}
\usepackage{amsthm}

\newtheorem{Theorem}{Theorem}

\newcounter{firstthm}
\newif\ifTheorem

\newcommand{\addtheorem}{\ifnum\value{firstthm}=0\relax
  \setcounter{firstthm}{\theTheorem}%
\fi
\global\Theoremtrue}

\fancyfoot[C]{\ifnum\value{firstthm}=0\relax
\else
  \ifnum\value{firstthm}=\value{Theorem}%
    Theorem \theTheorem
  \else
    \ifnum\value{firstthm}=\numexpr\value{Theorem}-1\relax
      Theorem \thefirstthm, \theTheorem
    \else
      Theorem \thefirstthm--\theTheorem
    \fi
  \fi
\fi
\ifTheorem
  \setcounter{firstthm}{\value{Theorem}}%
\else
  \setcounter{firstthm}{0}%
\fi}

\begin{document}

\pagestyle{fancy}

\begin{Theorem}\addtheorem
  This is the first theorem on page 1.
\end{Theorem}\Theoremfalse

\begin{Theorem}\addtheorem
  This is the second theorem on page 1.
\end{Theorem}
Here comes a proof of the second theorem which is continued on page 2. \\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.\\
Proof of this theorem.
\par\Theoremfalse

\begin{Theorem}\addtheorem
  This is the third theorem, which starts on page 2.
\end{Theorem}\Theoremfalse

\begin{Theorem}\addtheorem
  This is the fourth theorem, which starts on page 2.
\end{Theorem}\Theoremfalse

\begin{Theorem}\addtheorem
  This is the fifth theorem, which starts on page 2.
\end{Theorem}\Theoremfalse
\end{document}
4
  • Your answer works perfectly fine for my initial question. However, implementing it, I have just realized that i had simplified my MWE a little bit too much. Thus, I made the following slight changes: The environment of Theorem 2 ends already after the first sentence, followed by some text (the proof) outside the environment. Afterwards, there is a third theorem. I would now need the footer on the second page to be "Theorem 2, 3", but when implementing your solution I here get "Theorem 3" - sorry for not being precise enough in the beginning. Do you still have a solution for me?
    – Jack
    Commented Sep 22, 2019 at 21:33
  • Actually, I thought of another problem using \@currenvir, to wit a breakable environment INSIDE the Theorem environment. Commented Sep 23, 2019 at 14:46
  • Great - I now have a last question: If I have another two theorems on page 2 (i.e. in total four theorems on that page), is there a way to get "Theorem 2-5" instead of "Theorem 2, 3, 4, 5" in the footer (and still "Theorem 1, 2" on page 1)?
    – Jack
    Commented Sep 23, 2019 at 22:26
  • Theroem 1-2 would be easier. Instead of accumulating a list, you would just need to set a counter for the first theorem per page. Commented Sep 24, 2019 at 3:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .