[Tex/LaTex] Change TOC to use underline in subsubsections

capitalizationmemoirtable of contentstext-decorations

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?

Best Answer

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

enter image description here