3

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!

  • hi ! refere to : tex.stackexchange.com/questions/298073/… – flav Mar 24 '16 at 12:47
  • But with the dashrule package it is not possible to vertically align all dots to each other. right? – Phil Mar 24 '16 at 12:51
  • What do you want exactly ? Could you show us a picture ? – flav Mar 24 '16 at 12:53
3

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.

  • I tried your first example, but it won't work. I changed it to \contentsline{section}{\numberline{3.2.1}Verfügbarkeit}{7}{equation.3.2.1} and it worked. I'll try your second part of the answer soon. – Phil Mar 24 '16 at 13:21
  • Apparently, the number of arguments depends on whether hyperref is loaded and possibly on the document class. An automated method would definitely be best. – wrtlprnft Mar 24 '16 at 13:24
  • Second part also works, but the automation from the Link is not suitable for me. Nevertheless nice Answer! – Phil Mar 24 '16 at 15:23
1

You can set a new command that uses the same value of the ToC.

Output

enter image description here

Code

\documentclass{article}
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\newcommand\mydotfill{\cftdotfill{\cftdotsep}}

\begin{document}
\tableofcontents

\vspace{1cm}

\begin{itemize}
    \item[3.1] label\enspace\mydotfill\enspace 7
    \item[3.1] long label\enspace\mydotfill\enspace 7
    \item[3.1] very long label\enspace\mydotfill\enspace 7
\end{itemize}
\vspace{3cm}
\section{Verfügbarkeit}
\end{document}
  • Your dots aren't in a vertical row. The are shifted a little bit. I like to have each dot arranged exactly below the one above. – Phil Mar 24 '16 at 13:10
  • @Phil Why should they? One is a ToC entry, the other is an itemize entry. They aren't probably going to be in the same page anyways. Or do you want to enter custom entries in the ToC? – Alenanno Mar 24 '16 at 13:13
  • Soon I'll have more equations with different lengths of their names. I want to align all dots of the "list of equations" exactly among each other. I'll add a picture to my post. – Phil Mar 24 '16 at 13:25
  • haven't tested this, but ... the first line is bold, and the second isn't. what happens if the leaders are forced into \mdseries? – barbara beeton Mar 24 '16 at 13:57
  • 1
    @Phil As far as the itemize is concerned, adding longer labels is not an issue. See edit. – Alenanno Mar 24 '16 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.