6

In the memoir class, the "hangnum" chapterstyle puts the section numbers on the left margin, aligned right. How do I change it so that it is aligned left?

Here's an MWE with the original definition of the "hangnum" chapterstyle copied from the manual:

\documentclass[12pt]{memoir}

\usepackage[usehighlevels]{alnumsec}
\alnumsectionlevels{1}{section,subsection,subsubsection,paragraph}
\alnumsecstyle{aaaa}
\surroundarabic[{.}][]{}{}
\otherseparators{1}
\alnumsecstyle{aaaa}

\makechapterstyle{myhangnum}{%
\renewcommand*{\chapnumfont}{\chaptitlefont}
\settowidth{\chapindent}{\chapnumfont 999}
\renewcommand*{\printchaptername}{}
\renewcommand*{\chapternamenum}{}
\renewcommand*{\chapnumfont}{\chaptitlefont}
\renewcommand*{\printchapternum}{%
\noindent\llap{\makebox[\chapindent][l]{%
\chapnumfont \thechapter}}}
\renewcommand*{\afterchapternum}{}
}

\chapterstyle{myhangnum}
\hangsecnum

\begin{document}

\section{All these section numbers}
\subsection{should be aligned on the left}
\subsection{so that all the first digits}
\subsubsection{which is 1 in this case}
\paragraph{are underneath each other}\

Moreover, is it possible to decrease the space between 
the numbers and the titles? I rarely have paragraphs, 
but I have a lot of subsubsections.

\end{document}

I tried adding \hfill inside the makebox, altering the makebox parameters, but both to no avail:

\noindent\llap{\makebox[3cm][l]{%
\chapnumfont \thechapter \hfill}}}

I also tried altering the macro \chapternamenum (manual: is defined to be a space, is called between printing the chapter name and the number), but even if I enter a string in there, it does not shop up in the finished document.

  • I believe (I am no memoir expert, however) that myhangnum etc. is the wrong drill here. I think, it's rather \hangnumsec which has to be changed – user31729 Apr 11 '16 at 23:32
  • Try putting \fbox{...} around the boxes. This isn't to solve the problem - it will help you to see what is going on. At least, it often helps me. – cfr Apr 12 '16 at 1:15
1

Erh, one can just do this via

\setsecnumformat{\llap{%
    \makebox[\chapindent][l]{%
      \csname the#1\endcsname\hfill%
    }%
  }}

instead of issuing \hangsecnum, which by default is the same as

\setsecnumformat{\llap{\csname the#1\endcsname\quad}}}

@Ruben

Does this still fail at your end? I should be using the same memoir version, but is using TeLive 2015

\documentclass{memoir} 

\hangsecnum 
\setsecnumformat{\llap{\makebox[\chapindent][l]{\csname
      the#1\endcsname\hfill}}}

\chapterstyle{hangnum} 

\begin{document}

\chapter{A chapter}

\section{All these section numbers}
\subsection{should be aligned on the left}
\subsection{so that all the first digits}
\subsubsection{which is 1 in this case}

\end{document}
  • 1
    and you can control the space between section numbers and section title through changing the first parameter of \makebox (\chapindent in your example), nice! thanks a lot. – jpb Apr 12 '16 at 9:03
2

Here is a possibility, though it is very dirtily hacked:

\documentclass{memoir}
\usepackage[usehighlevels]{alnumsec}
  \alnumsectionlevels{1}{section,subsection,subsubsection,paragraph}
  \alnumsecstyle{aaaa}
  \surroundarabic[{.}][]{}{}
  \otherseparators{1}
  \alnumsecstyle{aaaa}
\usepackage{marginnote}
  \reversemarginpar
\usepackage{xpatch}

\chapterstyle{hangnum}

\makeatletter
\xpatchcmd\M@sect{\protected@edef}{\protected\def}{}{}
\xpatchcmd\@mn@@@marginnote{\@tempswatrue}{\@tempswafalse}{}{}
\marginparwidth 45\p@
\renewcommand{\printchapternum}{%
  \raisebox{5\p@}{\marginnote{\raggedright\chapnumfont\thechapter}}
}
\def\@seccntformat#1{\marginnote{\raggedright\csname the#1\endcsname}}
\makeatother

\begin{document}
\chapter{Some chapter}
\section{All these section numbers}
\subsection{should be aligned on the left}
\subsection{so that all the first digits}
\subsubsection{which is 1 in this case}
\paragraph{are underneath each other}
\end{document}

output_crop

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.