Search code examples
latexpage-numbering

Latex retake page numbering


so I am writing my thesis but I am asked to start page numbering in roman numbers, change to arabic, and then retake the numbering of roman numbers where it was left off, but I haven't found a way of doing it.


Solution

  • You need to manipulate some counters in order to achieve this. Extracting the saved values using refcount and converting them via expl3.

    enter image description here

    \documentclass{report}
    \usepackage{lipsum}% Just for this example
    \usepackage{refcount}
    \usepackage{xparse}
    
    \ExplSyntaxOn% http://tex.stackexchange.com/a/227859/5764
    \DeclareExpandableDocumentCommand{\arabicnumeral}{m}
      {
      \int_from_roman:n { #1 }
      }
    \ExplSyntaxOff
    \begin{document}
    \tableofcontents
    
    \clearpage
    \pagenumbering{roman}% Switch to roman numbering
    \chapter{First chapter}
    \lipsum[1-50]\lipsum[1-50]
    \label{last-roman-page}% Save last page of this chapter
    
    \clearpage
    \pagenumbering{arabic}% Switch to arabic numbering
    \chapter{Second chapter}
    \lipsum[1-50]\lipsum[1-50]
    
    \clearpage
    \renewcommand{\thepage}{\roman{page}}% Switch to roman numbering
    \edef\intpagevalue{\getpagerefnumber{last-roman-page}}% Retrieve last roman page & convert to arabic
    \setcounter{page}{\number\numexpr\expandafter\arabicnumeral\expandafter{\intpagevalue}+1}% Set current page value
    \chapter{Last chapter}
    \lipsum[1-50]\lipsum[1-50]
    
    \end{document}