3

In my essay, all parts before the text part have to be numbered in Roman numbers. After the title page, the table of contents gets the correct number I. The following pages containing sections are numbered with 1,2,... The minimal example will show this:

\documentclass{article}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[C]{}
\fancyfoot[R]{ 
        \footnotesize
        page \thepage\space of \pageref{LastPage} \\
}

\begin{document} 
\begin{titlepage}
This is the title.
\end{titlepage}
\pagenumbering{Roman}
\tableofcontents
\newpage
\pagenumbering{arabic}
\section{Section 1}
\subsection{Subsection 1.1}
\end{document}

However, the reference to the LastPage does not adapt to the defined \pagenumbering. As you will see, a line like this occurs:

page I of 1

My aim is to "split up" the LastPage reference in one for the "Roman" part at the beginning of the document and another one for the "arabic" part, for example:

page II of IV.....(and later on)......page 5 of 15

I already looked in the thread How can I add “page # of ##” on my document?, but I could not figure out an appropriate solution.

2
  • Do you have the option of restricting the "page x of y" page numbering system to the part of the document that starts with (arabic) 1?
    – Mico
    Apr 22, 2013 at 20:09
  • @Mico: Maybe this could be an option concerning formatting guideline...however, I do not know to restrict fancy to a certain area of pages. Could you please provide an example?
    – PWillms
    Apr 22, 2013 at 20:29

1 Answer 1

3

Here's a variant of an answer of mine

\documentclass{article}
\usepackage{refcount}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all fields
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{%
  \footnotesize
  page \thepage\space of \computelastpage
}

\usepackage{lipsum}

\makeatletter
\newif\if@mainmatter
\newcommand{\frontmatter}{%
  \clearpage
  \pagenumbering{Roman}
  \edef\computelastpage{%
    \uppercase{\romannumeral\numexpr\getpagerefnumber{LastFrontPage}-1\relax}}}
\newcommand{\mainmatter}{%
  \clearpage
  \immediate\write\@auxout{\noexpand\newlabel{LastFrontPage}{{}{\arabic{page}}}}%
  \@mainmattertrue
  \pagenumbering{arabic}
  \def\computelastpage{\pageref{LastPage}}}
\makeatother



\begin{document} 
\begin{titlepage}
This is the title.
\end{titlepage}

\frontmatter
\tableofcontents

\newpage

\lipsum

\mainmatter
\section{Section 1}
\subsection{Subsection 1.1}
\lipsum
\end{document}

I added some Lipsum paragraphs just to show the result. You have also a tidier document, by hiding \pagenumbering instructions in a higher level instruction.

The \mainmatter instruction writes a \newlabel referring to the just created new page, but before changing numbering. So the page number will be one more than the front matter final page. With a suitable definition of \computelastpage (which is different in front and main matter) we can refer to the number. Using \getpagerefcount provided by refcount is crucial.

You must log in to answer this question.

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