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.

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?

 \documentclass{article}
 \usepackage{etoolbox,graphicx}% http://ctan.org/pkg/{etoolbox,graphicx}
 \usepackage{xcolor}
 \usepackage{mdframed}

\definecolor{myblue}{RGB}{146,243,224}

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

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

\newcommand\mdframedintoc{\par\bigskip%
\begin{mdframed}[hidealllines=true,backgroundcolor=myblue]
\includegraphics[width=0.5\textwidth]{mypicture.png} 
 \end{mdframed}%
}
\patchcmd{\tableofcontents}{\@starttoc{toc}}{\@starttoc{toc}\mdframedintoc}{}{}
\makeatother


 \begin{document}

 \tableofcontents
 \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}

 \end{document}

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

\addstufftotoc{\vspace*{<len>}}

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

share|improve this answer

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.