Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My Table of Contents shows different spacing between lines when a chapter has sections and subsections and when it doesn't. I need the same spacing above ad below every chapter while keeping sections and subsections single spaced in the ToC. I'd appreciate any help.

share|improve this question
1  
Can you post a minimal example? Without it's pretty difficult to help you since you may have loaded a package which exactly does what you don't like. –  Uwe Ziegenhagen Dec 23 '12 at 18:14

1 Answer 1

The following works for the default document classes that support \chapter (report and book):

enter image description here

\documentclass{report}
\makeatletter
\let\old@makechapterhead\@makechapterhead
\renewcommand{\@makechapterhead}{%
  \addtocontents{toc}{\protect\addvspace{1.0em \@plus\p@}}%
  \old@makechapterhead%
}
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}
\makeatother
\begin{document}
\tableofcontents
\chapter{A chapter}\section{A section}\section{A section}
\chapter{A chapter}
\chapter{A chapter}\section{A section}\section{A section}
\chapter{A chapter}\section{A section}\subsection{A subsection}\subsection{A subsection}
\chapter{A chapter}
\end{document}

The solution does two things. It...

  1. ...modifies \l@chapter - the macro responsible for setting the chapter-related entry in the ToC - to use \addvspace instead of the "traditional" \vskip. This is just to ensure that there's no "doubling" of vertical spaces when adding more \vspace.
  2. ...uses \@makechapterhead to insert a vertical space (again, using \addvspace) into the ToC so that there's a space after the ToC entry.

Using a similar approach to the solution provided in Add dots in table of contents for parts for LaTeX document, adding dots to the chapter-entries in the ToC is possible via

\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak
      \xleaders\hbox{$\m@th % Added \xleaders
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
        mu$}\hfil\nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup
  \fi}

enter image description here

Instead of using \leaders, I've used \xleaders. The difference between these to leader types are discussed in Want to fill line with repeating string.

share|improve this answer
    
Thanks for your answer and explanation. How do I control the space between "Page" and the first item in toc? After the fix it added more space. Also chapters are bold, can I remove the boldface and add dotted line? –  user23612 Dec 23 '12 at 18:58
    
@user23612: Since the default ToC does not come with a "Page" label, could you include a minimal working example (MWE) that contains your current setup and add it to your original post? This should start with \documentclass, end with \end{document} and include some mock-up of a document as I did in my answer. –  Werner Dec 23 '12 at 19:05
    
Sorry is my first time using this forum. It gives me errors when I type LaTeX. I fixed the distance to Page issue, just need to add the dottedtocline. –  user23612 Dec 23 '12 at 19:11
    
Thsis works perfectly, thanks! –  user23612 Dec 25 '12 at 17:07
    
@user23612: Also see How do you accept an answer? –  Werner Dec 25 '12 at 17:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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