# Roman Numerals in ToC : Error in \settowidth

I have a document in which I was trying to replace the arabic numerals of the chapters by Roman Numerals in the TOC. i.e

Chapter 1  First chapter
Chapter 2  Second Chapter


I wanted

Chapter I:  First chapter
Chapter II: Second Chapter


I tried the following to get this

\documentclass[12pt,a4paper]{report}
\usepackage[titles]{tocloft}
%=================Content=======================
\newlength\mylength
\newcommand*{\Romannumeral}[1]{\uppercase\expandafter{\romannumeral#1}}
\renewcommand\cftchappresnum{\chaptername~\Romannumeral}
\renewcommand\cftchapaftersnum{:}
\settowidth{\mylength}{\cftchappresnum\cftchapaftersnum\space}
%=============Set Chapter in Page==============
\usepackage{titlesec}
\titleformat{\chapter}[display]{\normalfont\Large\bfseries\centering}{\chaptername\space\Roman{chapter}}{20pt}{\uppercase}
\begin{document}
\tableofcontents
\chapter{First}
first chapter
\section{first section}
first section
\section{second section}
second section
\subsection{first}
\chapter{Second}
second chapter
\section{first section}
first section
\end{document}


When I compile this get the following error

    ! Missing number, treated as zero.
:
l.8 ...th}{\cftchappresnum\cftchapaftersnum\space}

A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)


When I manually set the width as

\renewcommand\cftchapnumwidth{6em}


it compiles and shows the output correctly But due to variations in the size of chapter names it does not look great. So, How do I do this?

• Unrelated: tocloft and titlesec ... no good idea. – user31729 Jan 4 '17 at 13:23

\renewcommand\cftchappresnum{\chaptername~\Romannumeral}


is wrong, since \Romannumeral sees the \numberline{1} etc. statement, not the chapter number itself.

The whole thing is much easier, if \renewcommand{\thechapter}{\Roman{chapter}} is defined.

\documentclass[12pt,a4paper]{report}
\usepackage[titles]{tocloft}
%=================Content=======================
\newlength\mylength
\newcommand*{\Romannumeral}[1]{\uppercase\expandafter{\romannumeral#1}}
\renewcommand\cftchappresnum{\chaptername~}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand\cftchapaftersnum{:}
\settowidth{\mylength}{\cftchappresnum\cftchapaftersnum\space}
%=============Set Chapter in Page==============
\usepackage{titlesec}

\titleformat{\chapter}[display]{\normalfont\Large\bfseries\centering}{\chaptername\space\Roman{chapter}}{20pt}{\uppercase}
\begin{document}
\tableofcontents
\chapter{First}
first chapter
\section{first section}
first section
\section{second section}
second section
\subsection{first}
\chapter{Second}
second chapter
\section{first section}
first section
\end{document}