[Tex/LaTex] How to recreate the dotted line from the ToC

formattingtable of contents

Is there a command to draw a dotted line like the one in the table of contents?
I used \dotfill but this creates a row with a different spacing between the dots.

enter image description here

The dotted lines on top were created using

\begin{itemize}
    \item[3.1] Verfügbarkeit\enspace\dotfill\enspace 7
    \item[3.1] Verfügbarkeiit\enspace\dotfill\enspace 7
\end{itemize}

Here you can see that the dots of "Verfügbarkeiit" are not exactly below the ones from "Verfügbarkeit"

The ones below are the line of the ToC.

How can I achieve the same line?
Especially the fact that all dots are below each other (in a straight column)

Thanks!

Best Answer

The easy answer would be to just use \contentsline, since you probably want to copy the look of the other "list of x"es:

\contentsline{figure}{\numberline{3.2.1}Verfügbarkeit}{x}

The first parameter would be the entry type you want it to look like, for example section or chapter.

However, you could also automate the creation of your custom list of ..., which may be more maintainable in the long run.

One can also dig down into the definitons of the macros to find the magic that happens inside:

\show\contentsline
% results in #1->\csname l@#1\endcsname

So we see that the first parameter is used to complete a macro name, so let's see how this one expands:

\makeatletter
\show\l@figure
% results in ->\@dottedtocline {1}{1.5em}{2.3em}

Getting closer...

\show\@dottedtocline
% results in #1#2#3#4#5->\ifnum #1>\c@tocdepth \else \vskip \z@ \@plus .2\p@ {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip \parindent #2\relax \@afterindenttrue \interlinepenalty \@M \leavevmode \@tempdima #3\relax \advance \leftskip \@tempdima \null \nobreak \hskip -\leftskip {#4}\nobreak \leaders \hbox {$\m@th \mkern \@dotsep mu\hbox {.}\mkern \@dotsep mu$}\hfill \nobreak \hb@xt@ \@pnumwidth {\hfil \normalfont \normalcolor #5}\par }\fi

Ok, this is getting messy. But knowing that \leaders is responsible, we can isolate the interesting part of this command:

\leaders\hbox{$\m@th\mkern\@dotsepmu\hbox{.}\mkern\@dotsepmu$}\hfill

So if you want just the lines, but want them to look exactly like the tableofcontents ones, you could wrap this into a macro.

Related Question