# cftpartnumwidth - TOC not responding to changes

I posted the question here: http://www.latex-community.org/forum/viewtopic.php?f=47&t=11499&sid=ff51ce4bc05d87957773d360d33ffa91 but nobody answered, so I'm posting my question here ;]

I am using miktex 2.9. Compiling with pdflatex.

I want to increase the numwidth in TOC of part entry in article class to make titles of parts aligned to one line.

The minimal example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

\usepackage{tocloft}
\setlength{\cftpartnumwidth}{4em}
\cftsetindents{part}{0em}{4em}

\begin{document}
\tableofcontents
\part{Part1}
\part{Part2}
\part{Part3}
\part{Part4}
\part{Part5}
\part{Part6}
\end{document}


Neither seems to work:

\setlength{\cftpartnumwidth}{4em}
\cftsetindents{part}{0em}{4em}


I can easily modify numwidth of sections subsections etc. Changes are reflected in TOC.

While reading tocloft documentation it is stated:

There is no explicit numwidth for a part; instead a gap of 1em is put between the number and the title text.


Any ideas? I will be grateful for help!

-

The only thing that comes to mind is a kludge, bound to have unwanted effects, whereby you redefine the Part number display command \thepart to force it to a fixed width. (Of course this will also affect the actual Part titles and cross-references to them, etc.) For left-aligning:

\renewcommand{\thepart}{\hbox to 4em{\Roman{part}}}

For right:

\renewcommand{\thepart}{\hbox to 4em{\hfil\Roman{part}}}

I'm surprised you're using part divisions in an article, however... Are you sure you don't want to use sections instead? This would give you more flexibility.

-
Well it is a thesis not an article, I will have 20 sections and this number begs to divide and group into parts such as: Introduction, Main Part, Summary and mayby the main part into part devoted to deep theoretical background and part where I use it to create a solution. – Ujujinsan Jan 25 '11 at 23:54

Solution 1 (Best) This is a solution I made using frabjous suggestion using tocloft and titlesec. There is a hack using the let command and titlesec package for managing titles.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

\usepackage{tocloft}
\usepackage[explicit]{titlesec}
\let\theRpart\thepart
\renewcommand{\thepart}{\hbox to 4em{\Roman{part}}}

\newcommand{\partfont}{                    \fontsize{30pt}{36pt}   \bfseries  \selectfont }
\titleformat{\part}[display]
{ \partfont }
{  \ \vspace{35pt} \\ \filleft \partname \ \theRpart}
{15pt}
{ \filleft #1}
[\vspace{100pt}]
\begin{document}
\tableofcontents

\part{Part1}
This is a part
\newpage
\part{Part2}
This is a part
\newpage
\part{Part3}
This is a part
\newpage
\part{Part4}
This is a part
\newpage
\part{Part5}
This is a part
\newpage
\part{Part6}
This is a part
\newpage
\end{document}


Solution 2 (failed) The solution above is a kind of hack. It would be great if one could achieve it with titletoc package, however I do think that titletoc just like tocloft has problems with part in article class. Just a general not refined example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

\usepackage{tocloft}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}
\let\theRpart\thepart
%\renewcommand{\thepart}{\hbox to 4em{\Roman{part}}}

\newcommand{\partfont}{                    \fontsize{30pt}{36pt}   \bfseries  \selectfont }
\titleformat{\part}[display]
{ \partfont }
{  \ \vspace{35pt} \\ \filleft \partname \ \theRpart}
{15pt}
{ \filleft #1}
[\vspace{100pt}]
\titlecontents{section}[1.5em]{\vspace{40pt}}{ \contentslabel{2.3em}  }{   }{after  }[]
\titlecontents{part}[1.5em]{\vspace{40pt}}{ \contentslabel{2.3em}  }{   }{after  }[]
\begin{document}

\tableofcontents

\part{Part1}
This is a part
\section{ASDF}
\newpage
\part{Part2}
This is a part
\newpage
\part{Part3}
This is a part
\newpage
\part{Part4}
This is a part
\newpage
\part{Part5}
This is a part
\newpage
\part{Part6}
This is a part
\newpage
\end{document}


So in my opinion the hack that was created with frabjous suggestion is the only known valid way.

Solution 3 (failed) I was also trying :

\let\oldthepart\thepart
\renewcommand{\thepart}{...} %modified
\tableofcontents
\renewcommand{\thepart}{\oldthepart} %back to normal


But it failed miserably ;]

Solution 4 (success) One could however in the first run of latex run with command changing the hbox and the last run (when attaching TOC) without renewing \thepart command if one doesn't have the time to read into titlesec package.

Summary However the let command with titlesec package is the best solution in my opinion.

I'm leaving this question open for the time being.

-