# Custom left-aligned Veelo chapter style in Memoir

I'm trying to make a Memoir chapter style based on veelo, using this custom definition:

\documentclass[a5paper]{memoir}
\usepackage[utf8]{inputenc}

\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[showframe]{geometry}

\newlength{\numberheight}
\setlength{\numberheight}{15mm}
\makechapterstyle{myveelo}{%
\setlength{\afterchapskip}{30pt}
\renewcommand*{\afterchapternum}{\par\nobreak\vskip 10pt}
\renewcommand*{\chapnumfont}{\normalfont\Huge\bfseries}
\renewcommand*{\chaptitlefont}{\normalfont\Huge\bfseries}
\renewcommand*{\printchaptername}{}
\renewcommand*{\printchapternum}{%
\makebox[0pt][l]{%
\resizebox{!}{\numberheight}{\chapnumfont\thechapter}%
}%
\makebox[0pt][l]{%
\hspace{\textwidth}%
\hspace{1.5cm}%
\rule{2cm}{\numberheight}%
}
}%
\makeoddfoot{plain}{}{}{\thepage}
}

\chapterstyle{myveelo}

\begin{document}
\chapter{Introduction}
\lipsum[1]
\end{document}


An example chapter made with this (with showframe from the geometry package):

The problem is that the number is not aligned, and that the offset depends on the chapter number (1 is quite large, 4 is much smaller, etc.). Is there a way to left-align the number automatically for all chapter numbers?

• Please complete your snippet to a complete compilable example, starting with \documentclass and ending with \end{document}. Another comment, in your snippet you don't need \makeatletter and \makeatother since you are not using internal commands (containing @) Nov 25, 2021 at 23:58

You can apply a negative kerning depending on the initial digit.

I computed the following values by eye after looking closely them inside bounding boxes.

\documentclass[a5paper]{memoir}

\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[pass,showframe]{geometry}

\newlength{\numberheight}
\setlength{\numberheight}{15mm}
\makechapterstyle{myveelo}{%
\setlength{\afterchapskip}{30pt}
\renewcommand*{\afterchapternum}{\par\nobreak\vskip 10pt}
\renewcommand*{\chapnumfont}{\normalfont\Huge\bfseries}
\renewcommand*{\chaptitlefont}{\normalfont\Huge\bfseries}
\renewcommand*{\printchaptername}{}
\renewcommand*{\printchapternum}{%
\makebox[0pt][l]{%
\resizebox{!}{\numberheight}{\chapnumfont\fixspace{\thechapter}}%
}%
\makebox[0pt][l]{%
\hspace{\textwidth}%
\hspace{1.5cm}%
\rule{2cm}{\numberheight}%
}
}%
\makeoddfoot{plain}{}{}{\thepage}
}

\ExplSyntaxOn
\NewDocumentCommand{\fixspace}{m}
{
\martin_fixspace:e { #1 }
}
\cs_new_protected:Nn \martin_fixspace:n
{
\str_case_e:nn { \str_head:n { #1 } }
{
{0}{\kern-0.04em~}
{1}{\kern-0.08em~}
{2}{\kern-0.05em~}
{3}{\kern-0.0425em~}
{4}{\kern-0.03em~}
{5}{\kern-0.05em~}
{6}{\kern-0.045em~}
{7}{\kern-0.06em~}
{8}{\kern-0.045em~}
{9}{\kern-0.045em~}
}
#1
}
\cs_generate_variant:Nn \martin_fixspace:n { e }
\ExplSyntaxOff

\chapterstyle{myveelo}

\begin{document}
\chapter{Introduction}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.1pt}
\fbox{\chapnumfont\fixspace{0}}
\fbox{\chapnumfont\fixspace{1}}
\fbox{\chapnumfont\fixspace{2}}
\fbox{\chapnumfont\fixspace{3}}
\fbox{\chapnumfont\fixspace{4}}
\fbox{\chapnumfont\fixspace{5}}
\fbox{\chapnumfont\fixspace{6}}
\fbox{\chapnumfont\fixspace{7}}
\fbox{\chapnumfont\fixspace{8}}
\fbox{\chapnumfont\fixspace{9}}

\medskip

\noindent
\fbox{\chapnumfont 0}
\fbox{\chapnumfont 1}
\fbox{\chapnumfont 2}
\fbox{\chapnumfont 3}
\fbox{\chapnumfont 4}
\fbox{\chapnumfont 5}
\fbox{\chapnumfont 6}
\fbox{\chapnumfont 7}
\fbox{\chapnumfont 8}
\fbox{\chapnumfont 9}

\lipsum[1]
\end{document}


• I can't say I fully understand the solution, but it does what I want. Thanks! Jan 11 at 13:58
• @Martin The idea of \fixspace is to look at the first digit of its (expanded) argument. Then in front of this digit a negative kern is applied. Such kerns have bee visually computed and should be recomputed if you change the main font. Jan 11 at 14:04

Too long for a comment. This has nothing to do with memoir but rather a part of the font as can be seen from this example

\documentclass[a4paper]{memoir}
\newcommand\Show[1]{%
\begingroup%
\fboxsep=0pt%
\fbox{#11}%
\endgroup%
\par\medskip
}
\begin{document}
\Show{}
\Show{\large}
\Show{\Large}
\Show{\LARGE}
\Show{\huge}
\Show{\Huge}
\end{document}


The box around the number does not fit snugly and the effect is more noticeable as the font size gets larger

• So I suppose this means there is no solution then? Or is there a way to get the size of the number rather than the box, so I can offset the number to align nicely? Nov 26, 2021 at 9:24
• @Martin I usually do some tests with various numbers an then apply a negative kern to get it to the right place. There might be other methods. Nov 26, 2021 at 9:34
• @Martin chat mentions tex.stackexchange.com/questions/316964/… and tex.stackexchange.com/questions/470276/… though they probably need xelatex or lualatex Nov 26, 2021 at 10:36
• The digits in Computer Modern (and many other fonts) are monospace so that they align nicely in tables. Some fonts have a second set of digits that is spaced more like text. (And then there is the old style design, which can also come with two spacing settings.) These are all design decisions, and depend on the intended use. Numbers are not simple. Nov 26, 2021 at 14:54