1

this could seem a little awkward, but apparently I need to do it this way.

I have a document (class book) that uses arabic page numbering starting from the introduction page. Before that I have the \tableofcontents where I would like to show the page numbers as Roman, even when the real ones are numbered as arabic.

Example of wanted ToC:

  1. First chapter --- I
  2. Second chapter ---- X

But the real page number of the first chapter must be 1, second chapter must be 10, etc. I only need to transform the numbers to Roman on the ToC.

I've tried with this:

% ...
    \pagenumbering{Roman}
    \tableofcontents
    \pagenumbering{arabic}
    \setcounter{page}{1}
    \chapter{First chapter} % Page: 1
    % ... 
    \chapter{Second chapter} % Page: 10
% ...

But that just changes the pages where the ToC is, not the ToC itself, and that's not what I want.

3
  • Could you post a minimal (non-)working example that we can play with?
    – Bernard
    Aug 21, 2015 at 19:18
  • What is the rationale behind this awkwardness? Which page number style should be used by \pageref? Aug 21, 2015 at 19:49
  • \pagenumbering{arabic} should be preceded by \cleardoublepage.
    – egreg
    Aug 21, 2015 at 19:49

1 Answer 1

0

Typically all sectioning commands write \thepage to the ToC using \addcontentsline. You can update \addcontentsline to

\renewcommand{\addcontentsline}[3]{%
  \addtocontents{#1}{\protect\contentsline{#2}{#3}{\Roman{page}}}}

which writes \Roman{page} to the ToC instead of the default formatting \thepage (which may be different from \Roman{page}). A better option might be to patch \addcontentsline using etoolbox:

\usepackage{etoolbox}
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\addcontentsline}{\thepage}{\Roman{page}}{}{}

enter image description here

\documentclass[openany]{book}

\usepackage{etoolbox}
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\addcontentsline}{\thepage}{\Roman{page}}{}{}

\begin{document}

\tableofcontents

\clearpage
\pagenumbering{arabic}
\chapter{A chapter} % Page: 1
\section{A section}
\subsection{A subsection}

\clearpage
\setcounter{page}{10}
\chapter{Another chapter} % Page: 10
\section{Another section}
\subsection{Another subsection}
\end{document}
7
  • I don't think this makes sense.
    – egreg
    Aug 21, 2015 at 19:48
  • 1
    @egreg: The OP mentioned "this could seem a little awkward, but apparently I need to do it this way."
    – Werner
    Aug 21, 2015 at 19:49
  • 1
    No, it doesn't make any sense, but it's what I needed, thank you!! I have faith that the person responsible for writing this nonsense rule at my university will be punished eventually... and very badly. Aug 21, 2015 at 20:01
  • 1
    @Cataphractus: My suggestion using etoolbox works with hyperref, provided that the patch is performed after \usepackage{hyperref}.
    – Werner
    Aug 21, 2015 at 20:03
  • 5
    @Cataphractus: Are you sure that you get the rule right? Maybe the pages on which the TOC is printed should be numbered roman?! That makes lot more sense and is quite common …
    – Tobi
    Aug 21, 2015 at 20:10

You must log in to answer this question.

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