[Tex/LaTex] Change vertical space of chapters temporarly in Table of Contents

memoirspacingtable of contents

I have grouped sections nicely below of chapters in ToC, so that
there is no space between chapter and following sections, but there is
some space between last section and following chapter. All this is done using
memoir:

\setlength{\cftbeforesectionskip}{4pt}
\setlength{\cftbeforechapterskip}{16pt}

The problem is that chapter-like entries in the frontmatter (e.g. Foreword, Abstract)
will have relatively large vertical space in between. What I would like to have is
`groupedĀ“ frontmatter chapter-like entries with 4pt vertical space, and 16pt space between
last entry of the group (say, ToC or LoF) and the first chapter. Something like this:

Foreword
Abstract
List of Figures

Chapter 1 Introduction
  1.1 Section title
  1.2 Section title

Chapter 2 Theory
  2.1 Section title
  2.2 Section title

Bibliography

Best Answer

Here's one possible solution using the etoolbox package to patch the \chapter command to add some spacing to the ToC; the change is at the point the spacing is required:

\documentclass{memoir}
\usepackage{etoolbox}

\setlength{\cftbeforesectionskip}{4pt}

\begin{document}

\tableofcontents

\chapter*{Foreword}
\addcontentsline{toc}{chapter}{Foreword}
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}

\pretocmd{\chapter}{\addtocontents{toc}{\addvspace{16pt}}}{}{}

\chapter{Chapter One}
\section{Section One One}
\section{Section One Two}
\section{Section One Three}
\section{Section One Four}

\chapter{Chapter Two}
\section{Section Two One}
\section{Section Two Two}
\section{Section Two Three}

\chapter{Chapter Three}
\section{Section Three One}
\section{Section Three Two}
\section{Section Three Three}
\section{Section Three Four}
\section{Section Three Five}

\end{document}

The resulting ToC:

enter image description here