[Tex/LaTex] Minimum space between last word and page number in the table of content

formattingpage-numberingtable of contents

y question is, whether there is a solution to define a minimum blank space (length: three dots) between an entry's last word and the its page number within the table of contents?

Thanks a lot!

Update [08.01.2014]:

Hi! I have tried your solution, but interestingly, the space is connected to the page number's length. Thus the dots were removed if the page number increases (see my example).

\documentclass{scrbook}
\usepackage{tocstyle}
\usetocstyle{KOMAlike}
\settocstylefeature{pagenumberbox}{\hspace*{3em}}
\begin{document}
\tableofcontents
\chapter{chapter}
some text
\section{section}
some text\newpage
\setcounter{page}{10}
\section{Another section}
some text\newpage
\setcounter{page}{100}
\section{Next section}
some text\newpage
\setcounter{page}{1000}
\section{Guess! It's a section}
some text\newpage
\setcounter{page}{10000}
\section{Finally, the last section}
some text
\end{document}

This code result in the tiff-file below. How can I fix this problem?

Output

Best Answer

Since in your older questions you've always used the scrbook class, I'll assume that you are using it.

To make modifications to the ToC in KOMA classes usually the package tocstyle is used.

If you want to keep the normal ToC of KOMA classes use

\usetocstyle{KOMAlike}

and to achieve what you want use the line

\settocstylefeature[1]{pagenumberbox}{\hspace*{3em}}

Note that approximately each em corresponds to a dot you want to remove.

Also note that the optional argument [1] sets this behavior for \sections only (2 is for \subsections, etc.). If you want it for all sectioning commands, simply remove it.

MWE:

\documentclass{scrbook}
\usepackage{tocstyle}
\usetocstyle{KOMAlike}
\settocstylefeature[1]{pagenumberbox}{\hspace*{3em}}
\begin{document}
\tableofcontents
\chapter{chapter}
some text
\section{section}
some text
\end{document}

Output:

enter image description here


EDIT

To obtain what you have described in your edited question, it is better to resort to the titletoc package, issuing the command

\contentsmargin{3em}

MWE:

\documentclass{scrbook}
\usepackage{titletoc}
\contentsmargin{3em}

\begin{document}
\tableofcontents
\chapter{chapter}
some text
\section{section}
some text\newpage
\setcounter{page}{10}
\section{Another section}
some text\newpage
\setcounter{page}{100}
\section{Next section}
some text\newpage
\setcounter{page}{1000}
\section{Guess! It's a section}
some text\newpage
\setcounter{page}{10000}
\section{Finally, the last section}
some text
\end{document} 

or, without any additional package, redefine the command \@pnumwidth to be

\makeatletter
\renewcommand{\@pnumwidth}{3em}
\makeatother

MWE:

\documentclass{scrbook}
\makeatletter
\renewcommand{\@pnumwidth}{3em}
\makeatother

\begin{document}
\tableofcontents
\chapter{chapter}
some text
\section{section}
some text\newpage
\setcounter{page}{10}
\section{Another section}
some text\newpage
\setcounter{page}{100}
\section{Next section}
some text\newpage
\setcounter{page}{1000}
\section{Guess! It's a section}
some text\newpage
\setcounter{page}{10000}
\section{Finally, the last section}
some text
\end{document} 

In both cases the output is:

enter image description here

Related Question