TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This refers to my previous question How to put image in table of contents?

 \usepackage{etoolbox,graphicx}% http://ctan.org/pkg/{etoolbox,graphicx}


\newcommand{\addstufftotoc}[2][toc]{% \addimagetotoc[<toc>]{<stuff>}

\patchcmd{\l@section}% <cmd>
{\begingroup}% <search>
{\begingroup\normalfont\Large\bfseries}% <replace>
 {}{}% <success><failure>



 \section{First section}
 \addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2    \baselineskip]{example-image-a}\par}
 \section{Second section}
 \addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2     \baselineskip]{example-image-b}\par}
 \section{Third section}
 \section*{Fourth section}
 \addcontentsline{toc}{section}{\protect\numberline{}Fourth section}
 \addtocontents{toc}{\protect\contentsline{section}{Section Name}{}}
 \section{Last section}
 \addstufftotoc{\nobreak\smallskip\protect\includegraphics[height=2  \baselineskip]{example-image-c}\par}


enter image description here

How can I control the spacing between Contents and First Section (Increase) and between fourth section and Section Name (Reduce)?

share|improve this question

At the appropriate location within your document, use the \addstufftotoc macro to insert vertical space in the ToC.

To add/reduce space, use


where <len> is positive [negative] to add [remove] space.

share|improve this answer

Your Answer


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.