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.

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

A sample

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.

share|improve this question
    
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

2 Answers 2

up vote 3 down vote accepted

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}

\addtocontents{toc}{\protect\booltrue{specialtoc}}

\tableofcontents

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

\addtocontents{toc}{\protect\boolfalse{specialtoc}}

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

enter image description here

share|improve this answer
    
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
2  
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}
\addcontentsline{toc}{chapter}{Foreword}
\chapter*{Abstract}
\addcontentsline{toc}{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.

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.