I am currently trying to customize a chapter style using the memoir package (i originally started with the veelo source code). The style is working but is not really scalable which i would like to change. The style code is shown below.
I see mainly two issues:
1. The box containing the chapter number is scaled by width so that the bar next to the chapter number does not exceed the right text margin. The problem arise when the chapter number exceeds 10 - then the individual number size will be downscaled alot so the current solution is not really consistent for longer documents.
2. There seems to be a small space between the bars (\rule) and the \resizebox. Is it possible to remove these so i don't have to make the "by eye" adjustment to fit the margin?
I have thought about trying something completely different than using \rule and \resizebox. Is it possible to make a \colorbox filling the entire textwidth and placing a box with a white background containing the chapter number on top of that colorbox? I have tried to search for a solution online but have had no luck so far, so i thought i would try out this forum

So any ideas how i could fix these issues? Thanks in advance.
Code: Select all
Code, edit and compile here:
\definecolor{myred}{rgb}{0.6,0,0}\makeatletter\makechapterstyle{customchpstyle}{%\setlength{\afterchapskip}{40pt}\renewcommand*{\chapterheadstart}{\vspace*{40pt}}\renewcommand*{\afterchapternum}{\par\nobreak\vskip 25pt}\renewcommand*{\chapnamefont}{\normalfont\Large\flushleft}\renewcommand*{\chapnumfont}{\normalfont\huge}\renewcommand*{\chaptitlefont}{\normalfont\huge\bfseries\flushleft}\renewcommand*{\printchaptername}{}\renewcommand*{\chapternamenum}{}\newlength{\redbarheight}\setlength{\redbarheight}{0.5em} % Setting the height of the bar\newlength{\chapnumboxlength}\setlength{\chapnumboxlength}{2em} % Setting the length of the box containing chapter number\newlength{\leftbarlength}\setlength{\leftbarlength}{1em} % Setting length of the bar left to the chapter number\newlength{\rightbarlength}\setlength{\rightbarlength}{\textwidth}\addtolength{\rightbarlength}{-\leftbarlength}\addtolength{\rightbarlength}{-\chapnumboxlength} % Adjusting the right bar to fit the text margin\addtolength{\rightbarlength}{-0.5em} % "By eye" adjustment.. - shouldn't really be there :(\renewcommand*{\printchapternum}{%\makebox[0pt][l]{%\color{myred}\rule{\leftbarlength}{\redbarheight} % Left bar\resizebox{\chapnumboxlength}{!}{\color{black}\chapnumfont\thechapter} % Chapter number\color{myred}\rule{\rightbarlength}{\redbarheight} % Right bar}%}%\makeoddfoot{plain}{}{}{\thepage}}\chapterstyle{customchpstyle}