3

I would like hanging, styled section numbers while using the memoir class. The answer customizing section formatting using memoir class (color and numbering) explains how to style just the numbers, and the answer Hang section number, but not subsection number in Memoir explains how to hang the section number. However, when I attempt to combine these, my styling vanishes!

The commands I am using are:

\setsecnumformat{\color{blue}\csname the#1\endcsname\quad}
\setsechook{\hangsecnum}

Is there a way to do this?

  • As you can see in jons answer, \hangsecnum is an already defined secnumformat. So line two kills the format you just set. You can just copy the inner code from jons answer, you're basically just missing \llap, then you do not need to redefine \hangsecnum – daleif Oct 25 '16 at 5:43
2

This should do what you want. It simply modifies \hangsecnum to be blue for the section number.

\documentclass[article]{memoir}
\usepackage{xcolor}
\setcounter{secnumdepth}{3}

\makeatletter
\renewcommand{\hangsecnum}{%
  \def\@seccntformat##1{%
    \makebox[0pt][r]{%
      \color{blue}%
      \csname the##1\endcsname
      \quad
    }%
  }%
}
\makeatother

\setsechook{\hangsecnum}
\setsubsechook{\defaultsecnum}

\begin{document}

\section{First Section}
\subsection{First Subsection}
\subsubsection{First Subsubsection}

I would like hanging, styled section numbers while using the memoir
class. The answer customizing section formatting using memoir class
(color and numbering) explains how to style just the numbers, and the
answer Hang section number, but not subsection number in Memoir
explains how to hang the section number. However, when I attempt to
combine these, my styling vanishes!

\section{Second Section}
\subsection{Second Subsection}
\subsubsection{Second Subsubsection}

I would like hanging, styled section numbers while using the memoir
class. The answer customizing section formatting using memoir class
(color and numbering) explains how to style just the numbers, and the
answer Hang section number, but not subsection number in Memoir
explains how to hang the section number. However, when I attempt to
combine these, my styling vanishes!

\end{document}
  • Avoid \llap in the wild. And resetting the color is not needed, because \makebox groups its contents. The fact that memoir uses \llap in \hangsecnum is irrelevant (it's wrong to begin with). – egreg Oct 25 '16 at 7:05
  • @egreg -- that redefinitely looks tidier, thanks. (I was simply trying to mimic -- and show -- the original definition of \hangsecnum.) Not that I use them much, but is there a simple reason why \llap (and \rlap?) should be avoided? – jon Oct 25 '16 at 15:39
  • Unlike \makebox, \llap and \rlap don't start horizontal mode, if found in vertical mode. Not a real problem there, but when not writing package code it's better to use the safer version; \makebox is also color savvy, which \llap may not be. – egreg Oct 25 '16 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.