# Change TOC to use underline in subsubsections

I am using the package memoir and I need to redefine the fonts in TOC with this rules:

• For Chapters: all-caps and bold
• For Sections: bold
• For SubSections: bold and italic
• For SubSubSections: bold and underline
• For SubSubSubSections: nothing to do

I had success to configure sections:

\renewcommand{\cftsectionfont}{\bfseries}


subsections:

\renewcommand{\cftsubsectionfont}{\bfseries\itshape}


But for chapters, I didn't have success to use \MakeUppercase:

\renewcommand{\cftchapterfont}{\MakeUppercase\bfseries}


and for subsubsections, I didn't have success to put on underline

\renewcommand{\cftsubsubsectionfont}{\bfseries\underline}


So, how I put underline and uppercase?

\MakeUppercase and \underline are not font declarations. One has to work harder to achieve the result you want and that, personally, I don't like at all.

\documentclass{memoir}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@chapapp}
{\cftchapterfont #1}
{\cftchapterfont\MakeUppercase{#1}}
{}{}

\patchcmd{\l@subsubsection}
{#1}
{\ric@subunderline{#1}}
{}{}

\AtBeginDocument{
\ifnum\value{secnumdepth}>\tw@
\def\ric@subunderline#1{\ric@@subunderline#1\@nil}
\def\ric@@subunderline#1#2#3\@nil{#1{#2}\underline{#3}}
\else
\def\ric@subunderline#1{\underline{#1}}
\fi
}
\makeatother

%%% Fonts
\renewcommand{\cftchapterfont}{\bfseries}
\renewcommand{\cftsectionfont}{\bfseries}
\renewcommand{\cftsubsectionfont}{\bfseries\itshape}
\renewcommand{\cftsubsubsectionfont}{\bfseries}

\settocdepth{subsubsection}
\setsecnumdepth{subsubsection}

\begin{document}
\frontmatter
\tableofcontents*
\mainmatter
\chapter{Some title}
\section{Some title}
\subsection{Some title}
\subsubsection{Some title}
\end{document}


• Hum, but when I use hyperref package this solution didn't work. hyperref is incompatible with this? – Ric May 2 '13 at 23:24
• @Ric With hyperref it's really a different matter, I'm afraid. – egreg May 2 '13 at 23:29
• \MakeUppercase only works on simple text. When hyperref is added the hyperlink is added before \MakeUppercase gains access to it, thus is becomes too complicated for \MakeUppercase. The next memoir will have a workaround for this particular example (for \chapter, \part and\book) – daleif May 3 '13 at 8:14

Here is to achieve what you want, maintaining hyperref compatibility:

\documentclass{memoir}
%%% to check compatibility
\usepackage{hyperref}

%%% re-styling the TOC with etoc:
\usepackage{etoc}
\makeatletter
\let\old@chapter\l@chapter
\let\old@chapternumberline\chapternumberline
\etocsetstyle{chapter}{}{}
{\old@chapter{\old@chapternumberline{\etocnumber}%
\let\old@section\l@section
\etocsetstyle{section}{}{}
{\old@section{\numberline{\etocnumber}\etocname}{\etocpage}}{}%
\let\old@subsection\l@subsection
\etocsetstyle{subsection}{}{}
{\old@subsection{\numberline{\etocnumber}\etocname}{\etocpage}}{}%
\let\old@subsubsection\l@subsubsection
\etocsetstyle{subsubsection}{}{}
{\old@subsubsection{\numberline{\etocnumber}\underline{\etocname}}{\etocpage}}{}%
\makeatother

%%% Fonts
\renewcommand{\cftchapterfont}{\bfseries}
\renewcommand{\cftsectionfont}{\bfseries}
\renewcommand{\cftsubsectionfont}{\bfseries\itshape}
\renewcommand{\cftsubsubsectionfont}{\bfseries}

\settocdepth{subsubsection}
\setsecnumdepth{subsubsection}

\begin{document}
\frontmatter
\tableofcontents*
\mainmatter
\chapter{Some title}
\section{Some title}
\subsection{Some title}
\subsubsection{Some title}
\end{document}