# Change all section headings' colour while using memoir

I recently converted a document from book to memoir. It turns out that sectsty is incompatible. I used to have this:

\usepackage{sectsty}
\allsectionsfont{\color{blue}}

which very conveniently changed all my section headings' colours, including chapter, sections and subsections. What's the closest I can get for memoir?

• A solution found here that colors only the titles. – NBur Jun 21 at 10:51

The memoir class provides plenty of hooks for doing this sort of thing, but chapters and sections are treated differently. The \printchaptername macro prints the chapter name. Since we don't want to redefine it, I have used the \addtodef macro to prepend the \color macro to its definition, leaving the rest unchanged.

Depending on how you want the Table of Contents to look like, there are two different macros that can be changed. If you only want the TOC title changed, a different patching macro \addtoiargdef is used, since that macro takes an argument and cannot be patched with addtodef.

For the section formatting, there is an empty hook for each sectioning level which is initially set to {}. There is a macro \setSstyle (where S stands for the sectioning level (sec, subsec, subsubsec).

\documentclass{memoir}
\usepackage{xcolor}
\addtodef{\tocheadstart}{\color{blue!50!black}}{} % If you want the whole TOC to be blue also
%\addtoiargdef{\printtoctitle}{\color{blue!50!black}}{} % If you just want the TOC title blue
\begin{document}
\frontmatter
\tableofcontents*
\mainmatter
\chapter{A chapter}
\section{A section}
\subsection{A subsection}
\appendix
\chapter{An appendix}
\section{A section}
\subsection{A subsection}
\end{document}

• If I add “some text” between each sectionning command, only the one after \chapter{A chapter} appears in black… – NBur Jun 21 at 10:49
• @NBur Thanks for pointing this out. It's odd the OP accepted it with not comment. I've updated the answer. – Alan Munn Jun 21 at 14:13
• @NBur Sorry that was a typo in my correction. I should have copied the code I tested. :) – Alan Munn Jun 21 at 15:07