# Dotted line in ToC despite \cftsetpnumwidth

Using the package tocloft I have a problem with the dotted line in my ToC. For I'm using roman page numbering I have numbers of about XXVIII or something like that which is too wide for the obviously pre-set \pnumwidth. It flows of my right margin which looks quite unaesthetic. So to get the numbering ragged right I put the numbers into a box with \cftsetpnumwidth{}.

Now the problem is that the dotted line stops when reaching that box (which I know is quite obvious). But can I somehow get the dots until the number starts? Something like setting the pagenumbering raggedright with another command without using a numberbox? If anybody knows a solution for that problem I would be very happy to hear! Thanks in advance!

In the following my minimal example:

\documentclass[listof=totocnumbered,9pt,a4paper,ngerman]{scrartcl} % Verzeichnisse im IV aufgeführt mit Nr.

\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{extsizes}
\usepackage[a4paper,left=3cm,right=2.5cm,top=2cm,bottom=2cm]{geometry}
\usepackage[titles]{tocloft} % Formatierung der Vezeichnisse

\cftsetpnumwidth{1.0cm}

\renewcommand{\cftsecdotsep}{\cftdotsep}

\begin{document}
\makeatletter
\renewcommand{\cftdotsep}{0.5} % Einstellung der Punktabstände im VZ
\makeatother

\tableofcontents % Inhaltsverzeichnis

\newpage
\newcommand*{\thesectionwas}{}
\let\thesectionwas\thesection
\renewcommand{\thesection}{\Roman{section}}
\setcounter{section}{0}

\section{Abkürzungsverzeichnis}

\newpage
\makeatletter
\renewcommand{\cftdotsep}{0.5}
\makeatother
\listoffigures % Abb-VZ

\newpage
\makeatletter
\renewcommand{\cftdotsep}{0.5}
\makeatother
\listoftables % Tab-VZ
\newpage

\renewcommand{\thesection}{\Roman{section}}
\setcounter{section}{3}
\pagenumbering{Roman}
\setcounter{page}{31}

\begin{appendix}
\refstepcounter{section}
\section{bla}
\section{blabla}
\end{appendix}

\end{document}


Due to the general nature of tocloft, it sets all page numbers in a box of width \@pnumwidth. A quick fix to remove the boxing nature and in line with what you're after (right-aligned, "variable-width" page number boxes) is to remove the \makebox[<width>][<alignment>]{<stuff>} capability:

{\def\makebox[#1][#2]#3{#3}%
\tableofcontents % Inhaltsverzeichnis
}


The above temporarily makes \makebox a no-op during the setting of \tableofcontents.

\documentclass[listof=totocnumbered,9pt,a4paper,ngerman]{scrartcl} % Verzeichnisse im IV aufgeführt mit Nr.

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{extsizes}
\usepackage[a4paper,left=3cm,right=2.5cm,top=2cm,bottom=2cm]{geometry}
\usepackage[titles]{tocloft} % Formatierung der Vezeichnisse

\cftsetpnumwidth{1.0cm}

\renewcommand{\cftsecdotsep}{\cftdotsep}

\begin{document}
\makeatletter
\renewcommand{\cftdotsep}{0.5} % Einstellung der Punktabstände im VZ
\makeatother

{\def\makebox[#1][#2]#3{#3}%
\tableofcontents % Inhaltsverzeichnis
}

\newpage
\newcommand*{\thesectionwas}{}
\let\thesectionwas\thesection
\renewcommand{\thesection}{\Roman{section}}
\setcounter{section}{0}

\section{Abkürzungsverzeichnis}

\newpage
\makeatletter
\renewcommand{\cftdotsep}{0.5}
\makeatother
\listoffigures % Abb-VZ

\newpage
\makeatletter
\renewcommand{\cftdotsep}{0.5}
\makeatother
\listoftables % Tab-VZ
\newpage

\renewcommand{\thesection}{\Roman{section}}
\setcounter{section}{3}
\pagenumbering{Roman}
\setcounter{page}{31}

\begin{appendix}
\refstepcounter{section}
\section{bla}
\section{blabla}
\end{appendix}

\end{document}

• Your example seems to be exactly what I wanted, but when I copy your code into my Texmaker I can't compile it. I get the fault indications: "! Paragraph ended before \l@section was complete." and " forgotten \endgroup definition with \def\par Abkürzungsverzeichnis" even if all } are in their right place. I tried your command as well in my file and it didn't change my TOC, I still got the space between dotted line and pagenumber (but no fault indication). Do I have to add specified numbers into the [#1] or something? Or do I have to remove other commands like \@pnumwidth to make it work? – kinske Sep 24 '13 at 9:15
• @kinske: You have to compile at least twice, since you're dealing with ToC-related content (which influence is only noticeable with a 1 compile delay). I did change the inputenc from latin1 to utf8 which may explain the problem. The only thing you should need is {\def\makebox[#1][#2]#3{#3}\tableofcontents} and that's it. If that doesn't work, post what you have (if it's small, post it here, otherwise on PasteBin and post the link here) and we'll figure it out. – Werner Sep 24 '13 at 14:19
• Sorry it took me so long to answer, I had to hand in my Bachelors-Thesis so I was in a hurry, I now had time to come back to the problem: I compiled it more than twice and it didn't work as yours did. It seems as if I cannot use the utf8 encoding for my document, I get the fault indication "Keyboard character used is undefined (inputenc) in inputencoding utf8'". When using latin1 I can compile it without faults. I pasted my whole minimal example with all packages (maybe that is the problem?) I used at PasteBin, the link is: pastebin.com/ubgzWeY7 – kinske Oct 8 '13 at 20:34
• @kinske: When I compile with \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}` and have the file saved as a UTF-8 encoded file, things compile fine. I'm using TeXnicCenter under Windows. – Werner Oct 13 '13 at 5:11