34

I am writing an important document which has ended up being 13 pages.

For superstitious reasons, I want the page number on the last page to show up as "12+1". In other words, I want the page numbers to be: 1, 2, …, 11, 12, 12+1.

How do I do this?

3 Answers3

49

Define a new counter format:

\documentclass{article}

\usepackage{kantlipsum} % for mock text

\makeatletter
\newcommand{\fixedarabic}[1]{%
  \expandafter\@fixedarabic\csname c@#1\endcsname
}
\newcommand{\@fixedarabic}[1]{%
  \ifnum#1=13 12${}+{}$1\else\number#1\fi
}
\makeatother

\pagenumbering{fixedarabic}

\begin{document}

\kant[1-50]

\end{document}

enter image description here

egreg
  • 1,121,712
  • 22
    12+1 is much to obvious. I suggest $\sum_{i=1}^5 i -3$. – Ulrike Fischer Sep 11 '18 at 10:18
  • 2
    For my own understanding, could you comment on the differences between defining a new counter format and only redefining \thepage as follows: \renewcommand{\thepage}{\ifnum13=\value{page}12+1\else\the\value{page}\fi}? (The latter also works.) – Max Sep 11 '18 at 10:25
  • 1
    @Max More general. – egreg Sep 11 '18 at 10:28
  • 6
    Many thanks! This worked. It was my first time posting a question here and I am amazed how quickly help came. Thank you all! – Amir Ali Ahmadi Sep 11 '18 at 10:49
  • @UlrikeFischer that evaluates to zero – Maya Sep 11 '18 at 14:49
  • 1
    @NieDzejkob No, to 12, which is different from 13 anyhow. ;-) – egreg Sep 11 '18 at 14:50
  • @egreg ;-). I should check my sums better. – Ulrike Fischer Sep 11 '18 at 19:00
  • @NieDzejkob It depends if one interprets it as $\sum (i-3)$ or $(\sum i) - 3$. As far as I know in mathematics there is not a convention set in stone for the operator precedence of summation symbols. – Federico Poloni Sep 12 '18 at 08:22
  • @FedericoPoloni True. Still, it is genuinely understood that unless obviously/specifically otherwise, $\sum a+b = b+\sum a$. – yo' Sep 12 '18 at 09:00
  • 1
    @HenriMenke Nobody should be using \thepage for testing with \ifnum: what if we're under \pagenumbering{roman}? Heiko Oberdiek's answer to the first listed question in the link clarifies this. – egreg Sep 12 '18 at 09:06
  • @egreg I know, that's why I linked the site search to show that people do this and sometimes even recommend this as an answer. Your thing should blow up if used in \ifodd to prevent such misuse rather than giving a wrong result on only one page of the document (\relax\ifnum#1... should do it). – Henri Menke Sep 12 '18 at 09:09
  • @HenriMenke If a user says \def\fi{\mathop{fi}} in order to define a math operator, they're on their own. Using wrong tools can lead to harm oneself. A way out could be using $12+1$, but this could lead to page numbers being printed differently from the rest of the document; $\mbox{12}+\mbox{1}$ seems to me quite clumsy. – egreg Sep 12 '18 at 09:15
17

It could be a complex solution to convert the counter page to "12+1" if the value reach 13, but if only matter when 13 is the last page, why not simply change the footer just before \end{document} to "12+1"?.

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
aaa 
\setcounter{page}{12} % this is the 12th page
\newpage
bbb
\cfoot{12+1} % this is the 12+1th page 
\end{document}
Fran
  • 80,769
  • Thank you very much -- this is a quick solution too. The fancy page style created issues for me elsewhere, so I decided to go with the other proposed solution.

    Many thanks everyone.

    – Amir Ali Ahmadi Sep 11 '18 at 10:50
  • 1
    @AmirAliAhmadi the fancyhdr package allow a ex­ten­sive con­trol of page head­ers and foot­ers so that issues probably can be solved with no effort, or maybe the footer can be fixed by another method without that package, but without a minimal working example showing these issues is not possible go further. – Fran Sep 11 '18 at 11:07
3

The following solution sets page 13 as 12+1 in whichever format your page numbering is set to. It uses fancyhdr to set the page number in the Centre of the footer.

enter image description here

\documentclass{article}

\usepackage{lipsum,fancyhdr}

\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0pt}% Remove header rule
\fancyfoot[C]{%
  \ifnum\value{page}=13
   $\mbox{\setcounter{page}{12}\thepage} + \mbox{\setcounter{page}{1}\thepage}$%
   \setcounter{page}{13}%
  \else
    \thepage
  \fi
}

\pagenumbering{roman} % Just as an example

\begin{document}

\sloppy\lipsum[1-50]\lipsum[1-50]

\end{document}
Werner
  • 603,163