# Chapter heading designs in KOMA-Script

I want to achieve two related designs for the chapter heading. Design 1 should have a vertical line at the outer (right) margin which has the chapter (or appendix) name and the title to the left and the chapternumber to the right in the margin. Design two is nearly the same but with an additional shaded colorbox for the chaptertitle.

## Design 1

I started with this code and modified it the following way:

\documentclass[%
fontsize=11pt,%
chapterprefix=false,
numbers=noenddot,
]{scrbook}

\usepackage{xcolor}

\definecolor{chaptercolor}{cmyk}{.48, .05, .91, 0}

\renewcommand*{\chapterformat}{%
\smash{\textcolor{chaptercolor}{\rule[-5pt]{2pt}{10cm}}}%
\enspace
\textcolor{chaptercolor}{\fontsize{70pt}{60pt}\selectfont\rlap{\mdseries\thechapter\autodot}}%
}

\renewcommand*\chapterlinesformat[3]{%
\parbox[b]{\dimexpr\textwidth-0.5em\relax}{
\raggedleft{
\textcolor{chaptercolor}{\large\scshape\chapapp}
\par
\Huge\bfseries#3}
}%
\hfill
\makebox[0pt][l]{#2}%
}

\usepackage{blindtext}

\begin{document}
\tableofcontents
\chapter{Chapter One}
\blindtext
\chapter{Chapter Two with a very long title to see how the heading looks with a linebreak}
\blindtext
\appendix
\chapter{First Appendix}
\blindtext
\end{document}


This shows what I get on the left side and what I want at the right side (I added some pink and blue lines for orientation).

As you can see, the short chaptertitle is perfect as I want it. The number is on the (blue) bottom line of the chaptertitle and a little higher than the (pink) top line of the chapterprefix. For long chaptertitles I would like to have the number aligned to the blue line, too, which should be the bottom of the first line.

For the unnumbered chapters, the vertical line is missing. In addition, I couldn't manage to remove the chapterprefix from the unnumbered chapters. When I use \chapappifchapterprefix instead of \chapapp I get error warnings. If I use chapterprefix=true the whole layout gets messed up. The same happens, when I try to add the \chapapp into the \chapterformat definition.

## Design 2

I tried to include the colorbox into Design 1 the following way:

\documentclass[%
fontsize=11pt,%
chapterprefix=false,
numbers=noenddot,
]{scrbook}

\usepackage{xcolor}
\usepackage[framemethod=TikZ]{mdframed}

\definecolor{chaptercolor}{cmyk}{.48, .05, .91, 0}

\newmdenv[
innertopmargin=\topskip,
hidealllines=true,
skipabove=0pt,
skipbelow=0pt,
apptotikzsetting={\tikzset{
mdfframebackground/.append style={
left color= white,
right color=chaptercolor,
}}},
]{chapterbox}

\tikzset{
outer sep = 0pt,
inner sep = 5pt,
align = left,
text = white,
},
left color= white,
right color=chaptercolor,
font = \Huge\bfseries,
align=right,
text = black,
},
}

\newcommand{\newcolorboxedsec}[1]{%

\renewcommand*{\chapterformat}{%
\smash{\textcolor{chaptercolor}{\rule[-5pt]{2pt}{10cm}}}%
\enspace
\textcolor{chaptercolor}{\fontsize{70pt}{60pt}\selectfont\rlap{\mdseries\thechapter\autodot}}%
}

\renewcommand*\chapterlinesformat[3]{%
\parbox[b]{\dimexpr\textwidth-0.5em\relax}{
\raggedleft{
\textcolor{chaptercolor}{\large\scshape\chapapp}
}\par
}%
\hfill
\makebox[0pt][l]{#2}%
}

\usepackage{blindtext}

\begin{document}
\tableofcontents
\chapter{Chapter One}
\blindtext
\chapter{Chapter Two with a very long title to see how the heading looks with a linebreak}
\blindtext
\appendix
\chapter{First Appendix}
\blindtext
\end{document}


And again what I get on the left side and what I want on the right side with some orientation lines.

The short numbered chapter is quite close to what I want. But I don't know how to align the box and the vertical line and spread the box onto the left margin. (I never worked with tikz before.) Ans I also wonder why the box color is brighter and hence different from the chaptercolor I defined.

For unnumbered chapters and long chapters the same problems as for Design 1 persist. The number of long chapters should be at the same height as in short chapters, which this time is the (pink) baseline of the box (or the bottom line of letters like 'g' or 'p').

I would really appreciate if someone could help me fix these two designs. Thank you!

Here is another suggestion. Note, that shade transforms the color to rgb. If the color of the line should be the same as the right color of the shading, you have to define chaptercolor as rgb or RGB:

\documentclass[%
fontsize=11pt,%
chapterprefix=false,
numbers=noenddot,
draft,
]{scrbook}

\usepackage{lmodern}% scalable font to actually get the large numbers

\definecolor{chaptercolor}{RGB}{78,200,100}

\renewcommand\raggedchapter{\raggedleft}
\setkomafont{chapter}{\Huge}
\setkomafont{chapterprefix}{\large}
\newkomafont{chapternumber}{\mdseries\fontsize{50pt}{60pt}\selectfont}

\tikzset{
outer sep = 0pt,
inner sep = 5pt,
},
left color = white,
right color = chaptercolor,
},
text = chaptercolor,
font = \usekomafont{chapterprefix}
},
text = chaptercolor,
font = \usekomafont{chapternumber}
},
chaptercolor,
line width = 2pt
}
}
\makeatletter
\renewcommand*\chapterlinesformat[3]{%
\ifstr{#1}{chapter}{%
\begin{tikzpicture}[baseline=(title.base)]
\parbox[t]
{\dimexpr\textwidth-2\pgfkeysvalueof{/pgf/inner xsep}\relax}
{\raggedchapter #3}%
};
at (title.north east){\ifstr{#2}{}{}{\chapapp}\strut};
\useasboundingbox
(current bounding box.north west)
rectangle
([yshift=-10pt]current bounding box.south east);
(current bounding box.south east)++(+.5\pgflinewidth,0)--+(0,\paperheight);
at([xshift=10pt]title.base-|current bounding box.east){#2};
\end{tikzpicture}
\par
}{%
\@hangfrom{#2}{#3}% other section levels using style=chapter
}%
}
\makeatother

\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\chapter{Chapter One}
\blindtext
\chapter{Chapter Two with a very long title to see how the heading looks with a linebreak}
\blindtext
\appendix
\chapter{First Appendix}
\blindtext
\end{document}


• I added [\height]to the parbox in \node[headings/chapterbackground](title){...}to achieve the same box size for chapter with letters like 'g', 'p', etc. and chapters without these letters. (For example, when you compare 'Contents' with 'Chapter One'.) Mar 26, 2018 at 17:04

The following comes close to what you want in your second design.

\documentclass[%
fontsize=11pt,%
chapterprefix=false,
numbers=noenddot,
draft
]{scrbook}

\usepackage{xcolor}
\usepackage{tikz}
\usepackage{lmodern}% scalable font to actually get the large numbers

\definecolor{chaptercolor}{cmyk}{.48, .05, .91, 0}

\tikzset{
outer sep = 0pt,
inner sep = 5pt,
align = left,
text = white,
},
left color= white,
right color=chaptercolor,
font = \Huge\bfseries,
align=right,
text = black,
},
}

\newbox\LysanneBox
\newcommand{\newcolorboxedsec}[2]{%
\ifdim#1<\wd\LysanneBox
\else
\fi
}

\renewcommand*{\chapterformat}{%
\textcolor{chaptercolor}{%
\fontsize{50pt}{60pt}\selectfont\rlap{\mdseries\thechapter\autodot}%
}%
}

\renewcommand*\chapterlinesformat[3]{%
\mbox{}\hfill
\textcolor{chaptercolor}{\large\scshape\chapapp}~\mbox{}%
\smash{\raisebox{-\dimexpr\baselineskip+\parskip\relax}{\rlap{~#2}}}%
\par
\mbox{}\hfill
\llap{\newcolorboxedsec{\dimexpr\textwidth-1em\relax}{#3}~}%
\smash{\textcolor{chaptercolor}{\rule[-5pt]{2pt}{\paperheight}}}%
}

\usepackage{duckuments-devel}% better dummy content than blindtext :)

\begin{document}
\tableofcontents
\chapter{Chapter One}
\blindduck
\chapter{Chapter Two with a very long title to see how the heading looks with a linebreak}
\blindduck
\appendix
\chapter{First Appendix}
\blindduck
\end{document}


EDIT: Removing the chapter prefix for unnumbered chapters and the same box width for every heading. The colour issue is not fixed, as I honestly don't know what's wrong there and how to fix it.

\documentclass[%
fontsize=11pt,%
chapterprefix=false,
numbers=noenddot,
draft
]{scrbook}

\usepackage{xcolor}
\usepackage{tikz}
\usepackage{lmodern}% scalable font to actually get the large numbers

\definecolor{chaptercolor}{cmyk}{.48, .05, .91, 0}

\tikzset{
outer sep = 0pt,
inner sep = 5pt,
align = left,
text = white,
},
left color= white,
right color=chaptercolor,
font = \Huge\bfseries,
align=right,
text = black,
},
}

\newbox\LysanneBox
\newcommand{\newcolorboxedsec}[2]{%
}

\renewcommand*{\chapterformat}{%
\textcolor{chaptercolor}{%
\fontsize{50pt}{60pt}\selectfont\rlap{\mdseries\thechapter\autodot}%
}%
}

\renewcommand*\chapterlinesformat[3]{%
\mbox{}\hfill
\if\relax\detokenize{#2}\relax
\phantom{\textcolor{chaptercolor}{\large\scshape\chapapp}}~\mbox{}%
\else
\textcolor{chaptercolor}{\large\scshape\chapapp}~\mbox{}%
\fi
\smash{\raisebox{-\dimexpr\baselineskip+\parskip\relax}{\rlap{~#2}}}%
\par
\mbox{}\hfill
\llap{\newcolorboxedsec{\dimexpr\textwidth-1em\relax}{#3}}%
\smash{\textcolor{chaptercolor}{\rule[-5pt]{2pt}{\paperheight}}}%
}

\usepackage{duckuments-devel}% better dummy content than blindtext :)

\begin{document}
\tableofcontents
\chapter{Chapter One}
\blindduck
\chapter{Chapter Two with a very long title to see how the heading looks with a linebreak}
\blindduck
\appendix
\chapter{First Appendix}
\blindduck
\

• Oooooh, looks quite strange :-) Mar 25, 2018 at 16:52
• Thank you! We're getting closer. I removed the second ~ in chapterlinesformat to get the box aligned with the line (like a flag), but the colors don't mix, like the right side of the box has another green than the line. And how can I have the same boxsize for all headings (from left margin to the line at the right margin, no matter how long the title is)? And do you have any idea how to get rid of the chapterprefix for unnumbered chapters? Mar 25, 2018 at 17:35
• If I switch off the box color, I get exactly what I want for Design 1 (except for the chapterprefix). So this definetly helped. Mar 25, 2018 at 17:53
• @Lysanne see my edit, which solves the chapterprefix issue and the box width. Mar 25, 2018 at 18:03