[Tex/LaTex] Fancyhdr: How to change from lower case Roman numbers to upper case Roman number the pagenumbering of the preamble

fancyhdrpage-numbering

I am using the book class and I need to change the numbering of the first pages from lower case Roman numbers to upper case Roman numbers. I am using something like this:

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Title of the book}
\chead{}
\rhead{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

I believe I should use something like

\renewcommand{\pagenumbering}{Roman}

However, I am not able to access the page numbering of the preamble (I mean the first pages that include basically the table of contents.

Edit: [Minimal working example]

\documentclass[oneside,final,portrait,10pt]{book}

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{To do}
\chead{}
\rhead{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\pagenumbering{Roman}

\makeindex

\begin{document}

%\doublespace
\title{This book}
\author{Myself} \maketitle

\pagebreak

\frontmatter
\tableofcontents
\mainmatter

\chapter{Introduction}\label{capitulo_introducao}
%
%
This is my introduction

\end{document}

Best Answer

\frontmatter switches to roman (lower case) numbers, and \mainmatters switches back to arabic numbers, so if this should be prevented, it means either dropping \frontmatter and \mainmatter or patch this behaviour out of those macros using xpatchcmd from egreg's xpatch package.

I was a little bit lazy about the success/failure test of the command \xpatchcmd ;-)

\documentclass[oneside,final,portrait,10pt]{book}

\usepackage{xpatch}%

\xpatchcmd{\frontmatter}{\pagenumbering{roman}}{\pagenumbering{Roman}}{}{}%
\xpatchcmd{\mainmatter}{\pagenumbering{arabic}}{\pagenumbering{Roman}}{}{}%

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{To do}
\chead{}
\rhead{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\pagenumbering{Roman}

\makeindex


\begin{document}

%\doublespace
\title{This book}
\author{Myself} \maketitle

\pagebreak

\frontmatter
\tableofcontents
\mainmatter

\chapter{Introduction}\label{capitulo_introducao}
%
%
This is my introduction

\end{document}
Related Question