\newlength{\tocindent}
\setlength{\tocindent}{8pt}

\newlength{\tocchaptermargin}
\setlength{\tocchaptermargin}{-72pt}

\newlength{\tocsectionmargin}
\setlength{\tocsectionmargin}{\tocchaptermargin + \tocindent}

\newlength{\tocsubsectionmargin}
\setlength{\tocsubsectionmargin}{\tocsectionmargin + \tocindent}

\newlength{\tocsubsubsectionmargin}
\setlength{\tocsubsubsectionmargin}{\tocsubsectionmargin + \tocindent}

\newlength{\tocparagraphmargin}
\setlength{\tocparagraphmargin}{\tocsubsubsectionmargin + \tocindent}

\newlength{\tocsubparagraphmargin}
\setlength{\tocsubparagraphmargin}{\tocparagraphmargin + \tocindent}

\newlength{\tocdotspacing}
\setlength{\tocdotspacing}{6pt}

% Compensate for outdenting of section titles:
% This has no effect:
\renewcommand{\contentsname}{\sfont{1.4}\hspace*{1em}Contents}

\newcommand{\afternumberspace}{~~}

\newcommand{\numberlabel}{\parbox[b]{64pt}
  {\raggedleft\hspace*{8pt}\small\thecontentslabel}}
           
\renewcommand{\numberlabel}{\hspace*{-1\hoffset}\thecontentslabel\afternumberspace}

\newcommand{\pagenumber}{\parbox{\widthof{888}{\contentspage}}}

\newcommand{\tocpage}{~\titlerule*[\tocdotspacing]{.}
  \makebox[\widthof{\thecontentspage}][r]{\small\thecontentspage}}

\newcommand{\interline}{\vspace*{-6pt}}

\titlecontents{chapter}[\tocchaptermargin]
              {\vspace{6pt}\thispagestyle{noheader}}
              {\numberlabel}         
              {\hspace*{-12pt}}
              {\tocpage}
              [\interline]

\titlecontents{section}[\tocsectionmargin]
              {\ifthenelse{\equal{\documentisbook}{true}}{}{\vspace{6pt}}}
              {\numberlabel}
              {\hspace*{-18pt}}
              {\tocpage}
              [\interline]

\titlecontents{subsection}[\tocsubsectionmargin]
              {}
              {\numberlabel}
              {\hspace*{-24pt}}
              {\tocpage}
              [\interline]

\titlecontents{subsubsection}[\tocsubsubsectionmargin]
              {}
              {\numberlabel}
              {\hspace*{-30pt}}
              {\tocpage}
              [\interline]
 
\titlecontents{paragraph}[\tocparagraphmargin]
              {}
              {\numberlabel}
              {\hspace*{-36pt}}
              {\tocpage}
              [\interline]

\titlecontents{subparagraph}[\tocsubparagraphmargin]
              {}
              {\numberlabel}
              {\hspace*{-42pt}}
              {\tocpage}
              [\interline]
