# 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?

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 \setShook (where S stands for the sectioning level (sec, subsec, subsubsec). If you set this at the section level it will be inherited by the lower sections.

\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
\setsechook{\color{blue!50!black}}
\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}