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}
\renewcommand{\cftsecleader}{\normalfont\cftdotfill{\cftsecdotsep}}
\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}
Best Answer
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:The above temporarily makes
\makebox
a no-op during the setting of\tableofcontents
.