[Tex/LaTex] Alignment of modified veelo chapter style (memoir)

horizontal alignmentmemoir

I'm having some problems modifying the veelo chapter style. Due to my smaller margins (I need A5 paper size), the regular veelo didn't work correctly. So instead of having the chapter number in the margin, I want it to be right aligned to the text block (see figure). I am doing that now by hard-coding it, but due to the different width of the various number characters it doesn't consistently work for all chapters. Also, the black box that extends outside of the trim marks is left-aligned to the number, causing the box to have different sizes for different chapter numbers.

My question: could you check out my code below and tell me what I'm supposed to change to 1) right-align the number to the text block, and 2) make the black box have the same size regardless of the number width?

Thanks so much!

Example chapter page

\makeatletter
\newlength{\numberheight}
\setlength{\numberheight}{\beforechapskip}

\newlength{\barlength}

\makechapterstyle{myveelo}{%
\setlength{\afterchapskip}{40pt}
\renewcommand*{\chapterheadstart}{\vspace*{40pt}}
\renewcommand*{\afterchapternum}{\par\nobreak\vskip 25pt}
\renewcommand*{\chapnamefont}{\normalfont\LARGE\flushright}
\renewcommand*{\chapnumfont}{\normalfont\HUGE}
\renewcommand*{\chaptitlefont}{\normalfont\HUGE\bfseries\flushright}
\renewcommand*{\printchaptername}{%
\chapnamefont\MakeUppercase{\@chapapp}\hspace*{\midchapskip}}
\renewcommand*{\chapternamenum}{}
\setlength{\beforechapskip}{18mm}
\setlength{\midchapskip}{\paperwidth}
\addtolength{\midchapskip}{-\textwidth}
\addtolength{\midchapskip}{-\spinemargin}
\addtolength{\midchapskip}{-11.5em}
\renewcommand*{\printchapternum}{%
\makebox[0pt][l]{\hspace{-1.5cm}%
\resizebox{!}{\numberheight}{\chapnumfont \thechapter}%
\hspace{1.8em}%
\rule{\midchapskip}{\beforechapskip}%
}}%
\makeoddfoot{plain}{}{}{\thepage}}

\makeatother

Best Answer

Your redefinition of \printchapternum has to be changed to something like

\renewcommand*{\printchapternum}{%
  \enspace\resizebox{!}{\numberheight}{\chapnumfont\thechapter}%
  \rlap{\hspace{1cm}\rule{\midchapskip}{\beforechapskip}}%
}%

change the 1cm I used to separate the number and the filled square to the desired value.

The complete code:

\documentclass{memoir}
\usepackage{graphicx}

\makeatletter
\newlength{\numberheight}
\setlength{\numberheight}{\beforechapskip}

\makechapterstyle{myveelo}{
  \setlength{\afterchapskip}{40pt}
  \renewcommand*{\chapterheadstart}{\vspace*{40pt}}
  \renewcommand*{\afterchapternum}{\par\nobreak\vskip 25pt}
  \renewcommand*{\chapnamefont}{\normalfont\LARGE\flushright}
  \renewcommand*{\chapnumfont}{\normalfont\HUGE}
  \renewcommand*{\chaptitlefont}{\normalfont\HUGE\bfseries\flushright}
  \renewcommand*{\printchaptername}{%
    \chapnamefont\MakeUppercase{\@chapapp}}
  \renewcommand*{\chapternamenum}{}
  \setlength{\beforechapskip}{18mm}
  \setlength{\midchapskip}{\paperwidth}
  \addtolength{\midchapskip}{-\textwidth}
  \addtolength{\midchapskip}{-\spinemargin}
  \addtolength{\midchapskip}{-11.5em}
  \renewcommand*{\printchapternum}{%
    \enspace\resizebox{!}{\numberheight}{\chapnumfont\thechapter}%
    \rlap{\hspace{1cm}\rule{\midchapskip}{\beforechapskip}}%
  }%
  \makeoddfoot{plain}{}{}{\thepage}%
}

\chapterstyle{myveelo}
\makeatother

\begin{document}

\chapter{Test chapter}
\setcounter{chapter}{100}
\chapter{Test chapter}

\end{document}

An image of the output:

enter image description here

Related Question