# How to change chapter font style in the middle of the Table of the Contents?

What I do have, is grouped frontmatter entries (chapter-like) in ToC, and the rest of the chapters have larger vertical space.
What I want is to change the font style of the grouped part to, say, normalfont or italics while keeping the rest of the entries unchanged. How do I do this?

(In the future I might change entries of the chapters 1 to 3 to small caps or to something other format...)

\documentclass{memoir}
\usepackage{etoolbox}

\setlength{\cftbeforesectionskip}{4pt}

\begin{document}

\tableofcontents

\chapter*{Foreword}
\chapter*{Abstract}

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


This is continuation to the question Change vertical space of chapters temporarly in Table of Contents. Package etoolbox is for the grouping the front matter entries.

-
Found a solution, kind of... Add \renewcommand*{\cftchapterfont}{} to the preamble and change the \pretocmd... to \pretocmd{\chapter}{\addtocontents{toc}{\addvspace{16pt}\bfseries}}{}{}. Only problem is that if the grouped entries should be italics and the rest not, it won't work. – TKO Nov 19 '12 at 19:12

Declare a new boolean switch (say, specialtoc). Set it (inside the .toc file) to true at the start of the document body and to false at the start of the main chapters. Redefine \cftchapterfont and \cftchapterpagefont (which are responsible to format ToC chapter entries) so that their meaning depends on the state of specialtoc.

\documentclass{memoir}

\setlength{\cftbeforesectionskip}{4pt}

\usepackage{etoolbox}

\newbool{specialtoc}

\renewcommand{\cftchapterfont}{%
\ifbool{specialtoc}{%
\itshape
}{%
\bfseries
}%
}

\renewcommand{\cftchapterpagefont}{%
\ifbool{specialtoc}{%
\itshape
}{%
\bfseries
}%
}

\begin{document}

\tableofcontents

\chapter*{Foreword}
\chapter*{Abstract}

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


-
Nice! I can see that you can use specialtoc multiple times (or add other boolean switches) to change the appearance of, say, bibliography or appendices. As a side note, makes me wonder, why there is no options in memoir or a dedicated package to change the appearance of ToC to look like this - it does look better than the original! – TKO Nov 20 '12 at 6:58
I usually use the toc hooks to insert macro hooks into the toc file itself, and then in the preamble define what those hooks should do, I'm not a fan of changing \chapter. See \cftinserthook and \cftinsertcode, the later is for defining what a hook does. Adding things like locksteps solution would make memoir a lot more difficult to understand than it already is. – daleif Nov 20 '12 at 9:08
@daleif Because this question was continuation to other question, I used etoolbox. Your point makes this "nuisance" unnecessary, thank you! – TKO Nov 20 '12 at 10:02

Altough lockstep gave already very nice answer to the problem, I'll add minimal solution based on daleif's comment on \cftinserthook and \cftinsertcode. This way the etoolbox-package is not needed at all.

\documentclass{memoir}

\setlength{\cftbeforechapterskip}{4pt}
\renewcommand*{\cftchapterfont}{\itshape}

\cftinsertcode{SPECIALTOC}{%
\renewcommand*{\cftchapterfont}{\bfseries}%
\setlength{\cftbeforechapterskip}{16pt}%
}
\begin{document}

\tableofcontents

\chapter*{Foreword}
\chapter*{Abstract}

\cftinserthook{toc}{SPECIALTOC}

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

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

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

\end{document}


The output is similar to lokcstep's solution.

-