# Alignment of chapter, section and subsection in memoir class

I was wondering if there is a neat way of aligning the chapter, section and subsection headings in memoir class so as to look like this:

(the largest heading at the top is the chapter, etc.)

• What code have you got? What have you tried? Please provide a minimal example. – cfr Dec 8 '16 at 23:33

The following example provides a length \secnumwidth that is used to fix the widths within which the section numbers (including that of \chapter) is printed. All other display styles have been preserved (including the vertical spacing for \chapter):

\documentclass{memoir}

\newlength{\secnumwidth}
\setlength{\secnumwidth}{3em}

\renewcommand{\printchaptername}{}% Don't print 'Chapter'
\renewcommand{\chapnumfont}{\chaptitlefont}
\renewcommand{\afterchapternum}{}% Remove (vertical) skip between chapter number and title
\makeatletter
\renewcommand{\@seccntformat}[1]{\makebox[\secnumwidth][l]{\csname the#1\endcsname}}
\makeatother

\setcounter{secnumdepth}{2}% Number up to \subsection

\begin{document}

\chapter{A chapter}

\section{A section}

\subsection{A subsection}

\end{document}


Here's a similar way to achieve it in the default report document class. It involves updating \@makechapterhead and \@seccntformat:

\documentclass{report}

\newlength{\secnumwidth}
\setlength{\secnumwidth}{5em}

\makeatletter
\vspace*{50\p@}%
{\interlinepenalty\@M
\parindent \z@ \raggedright \normalfont
\huge\bfseries
\ifnum \c@secnumdepth >\m@ne
\makebox[\secnumwidth][l]{\thechapter}%
\fi
#1\par\nobreak
\vskip 40\p@
}}
\renewcommand{\@seccntformat}[1]{\makebox[\secnumwidth][l]{\csname the#1\endcsname}}
\makeatother

\begin{document}

\chapter{A chapter}

\section{A section}

\subsection{A subsection}

\end{document}


Like before, the regular vertical spacing for \chapter has been preserved (but could be changed).