2

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?

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

1 Answer 1

2

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

partial output

4
  • If I add “some text” between each sectionning command, only the one after \chapter{A chapter} appears in black…
    – NBur
    Jun 21, 2019 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, 2019 at 14:13
  • Adding the \setsubsecstyle{\color{blue!50!black}} changes nothing here :( As mentionned in stackoverflow.com/a/53578046/8668352, I use \set<(sub)(sub)sec/(sub)para>headstyle{\sffamily\color{red}} instead in cunjunction with \renewcommand{\<part/chapter>namefont}{<decl>}, \renewcommand{\<part/chapter>numfont}{<decl>} and \renewcommand{\<part/chapter>titlefont}{<decl>}
    – NBur
    Jun 21, 2019 at 14:44
  • @NBur Sorry that was a typo in my correction. I should have copied the code I tested. :)
    – Alan Munn
    Jun 21, 2019 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .