6

How do I reduce the vertical space before a part title in the ToC?

Here is what I have that's related to headers and their ToC entries (I think):

\documentclass{article}

\usepackage{titletoc}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries\hfil\partname~\thepart\hfil
       \par\nobreak
     \fi
     \huge\bfseries\sffamily\raggedleft #2%
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\makeatother

\makeatletter
  \@addtoreset{section}{part}
  \@addtoreset{subsection}{section}
  \@addtoreset{subsubsection}{subsection}
\makeatother
\titlecontents{section}[1.8em]{}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}[4.65em]{}{\contentslabel{2.85em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsubsection}[8.35em]{}{\contentslabel{3.75em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}

\renewcommand*\thepart{\arabic{part}}
\renewcommand*\thesection{\thepart.\arabic{section}}


\begin{document}

\tableofcontents
\newpage

\part{sxsafawf}
\section{sasrvth}

\part{sxsafawf}
\section{sasrvth}

\end{document}

output

3 Answers 3

5

I think you are talking about \part and not \chapter.

Since you are redefining the \part command, it suffices to add the line

\addtocontents{toc}{\protect\vspace*{-15\p@}}

in the redefinition (adjust -15\p@ to your needs).

MWE:

\documentclass{article}

\usepackage{titletoc}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addtocontents{toc}{\protect\vspace*{-15\p@}}% <------------ added
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addtocontents{toc}{\protect\vspace*{-15\p@}}% <------------ added
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries\hfil\partname~\thepart\hfil
       \par\nobreak
     \fi
     \huge\bfseries\sffamily\raggedleft #2%
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\makeatother

\makeatletter
  \@addtoreset{section}{part}
  \@addtoreset{subsection}{section}
  \@addtoreset{subsubsection}{subsection}
\makeatother
\titlecontents{section}[1.8em]{}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}[4.65em]{}{\contentslabel{2.85em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsubsection}[8.35em]{}{\contentslabel{3.75em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}

\renewcommand*\thepart{\arabic{part}}
\renewcommand*\thesection{\thepart.\arabic{section}}


\begin{document}

\tableofcontents
\newpage

\part{sxsafawf}
\section{sasrvth}

\part{sxsafawf}
\section{sasrvth}

\end{document} 

Output:

enter image description here

2

If you don't want to specify \titlecontents{part} and are satisfied by the default typesetting by the article class, it's sufficient to patch the original \l@part command, which titletoc calls \ttl@savel@part:

\documentclass{article}

\usepackage{titletoc}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\ttl@savel@part}{2.25em}{1em}{}{} % <--- adjust to suit

\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries\hfil\partname~\thepart\hfil
       \par\nobreak
     \fi
     \huge\bfseries\sffamily\raggedleft #2%
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\makeatother

\makeatletter
  \@addtoreset{section}{part}
  \@addtoreset{subsection}{section}
  \@addtoreset{subsubsection}{subsection}
\makeatother
\titlecontents{section}[1.8em]{}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}[4.65em]{}{\contentslabel{2.85em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsubsection}[8.35em]{}{\contentslabel{3.75em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}

\renewcommand*\thepart{\arabic{part}}
\renewcommand*\thesection{\thepart.\arabic{section}}


\begin{document}

\tableofcontents
\newpage

\part{sxsafawf}
\section{sasrvth}

\part{sxsafawf}
\section{sasrvth}

\end{document}

enter image description here

2

It suffices to also re-define the formatting of \part in the table of contents and give spacing parameters. By the way, writing

\@addtoreset{subsection}{section}
\@addtoreset{subsubsection}{subsection}

is useless — it is the default.

Here is a possibility:

\documentclass{article}

\usepackage{titletoc}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries\hfil\partname~\thepart\hfil
       \par\nobreak
     \fi
     \huge\bfseries\sffamily\raggedleft #2%
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\makeatother

\makeatletter
  \@addtoreset{section}{part}
  \@addtoreset{subsection}{section}
  \@addtoreset{subsubsection}{subsection}
\makeatother
\titlecontents{part}[0em]{\vspace{2ex}\bfseries}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}[\smallskip]
\titlecontents{section}[3.6em]{}{\contentslabel{1.8em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}[4.65em]{}{\contentslabel{2.85em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsubsection}[8.35em]{}{\contentslabel{3.75em}}{\hspace*{0em}}{\titlerule*[1pc]{.}\contentspage}

\renewcommand*\thepart{\arabic{part}}
\renewcommand*\thesection{\thepart.\arabic{section}}

\begin{document}

\tableofcontents
\newpage

\part{sxsafawf}
\section{sasrvth}

\section{another section}

\section{a third section}

\part{sxsafawf}
\section{sasrvth}

\end{document} 

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .