# Myheadings, markboth and page number

I assume I'm not understanding something about myheadings and markboth. Here is my MWE (I'm running this on MikTeX 2.9 on a Win10 box):

\documentclass{article}

\begin{document}

\pagestyle{myheadings}

\markboth{}{Why is this not the right number? \arabic{page}}

First page.

\newpage

Another page.

\newpage

And another.

\end{document}


In all of the three pages, \arabic{page} in the header prints 1, instead of the expected 1,2,3.

• Not sure what you're expecting: the \rightmark is set at the moment the \markboth command is processed. Nov 10, 2015 at 18:32

## 1 Answer

You're using the wrong tool for setting page numbers. Anyway, using \protect\thepage solves the issue, as it avoids \thepage being expanded at the moment \rightmark is assigned a value and deferring its evaluation to the header's print time.

\documentclass{article}

\begin{document}

\pagestyle{myheadings}

\markboth{}{Why is this not the right number? \protect\thepage}

First page.

\newpage

Another page.

\newpage

And another.

\end{document}