# Titlesec colored chapter accent reproduced in KOMA script

I am using this https://github.com/derric/cleanthesis template, but its combining titlesec and KOMA script which I would like to avoid.

Heres an example of the chapter style:

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

\newcommand\mychapformat[1]{%
\parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
{\usekomafont{chapter}\sectfont}%
{\vspace{-8em}\raggedleft{%
{\color{ctcolorchapterline}%
{\color{ctcolorchapternum}
\fontsize{60}{60}\selectfont\thechapter}%
}%
}%
{-2.1em}%
{\mychapformat}%
[\phantomsection]

\begin{document}

\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]

\end{document}


Is there a way I can reproduce the colored line and chapter number with chapter name linebreak using only KOMA script?

• What should happen if the number has two or three digits? – Ulrike Fischer Apr 5 '18 at 11:53
• Hm good question, for my case its not going to be more than one digit so esdd answer is perfect. – voiDnyx Apr 6 '18 at 11:43

Maybe the following helps:

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

\RedeclareSectionCommand[
beforeskip=-1sp
]{chapter}

\makeatletter
\renewcommand\chapterlinesformat[3]{%
\ifstr{#1}{chapter}
{%
\parbox[b][\ht\strutbox]{\textwidth}{%
\parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#3}%
\makebox[3em][r]{%
\hfill
#2%
}%
}%
}{\@hangfrom{#2}{#3}}% <- original definition for other levels
}
\makeatother
\renewcommand\chapterformat{%
\textcolor{ctcolorchapterline}{\rule[-5pt]{2pt}{5cm}}%
{\fontsize{60}{60}\selectfont\textcolor{ctcolorchapternum}{\thechapter}}%
}
\begin{document}
\tableofcontents
\chapter{A test chapter with a long title that will span two lines}
\lipsum[4]
\chapter{Chapter with short title}
\lipsum
\end{document}


Note that this suggestion is limited to one digit numbers (like your MWE).

Update regarding the usage appendixprefix=true

As mentioned in your comment below you want to set appendixprefix=true. So I assume that you want to use the default layout for chapter titles in appendix. Then you have to change the redefinition of \chapterformat to

\renewcommand\chapterformat{%
\IfUsePrefixLine{%
\mbox{\chapappifchapterprefix{\nobreakspace}\thechapter\autodot\enskip}%
}{%
\textcolor{ctcolorchapterline}{\rule[-5pt]{2pt}{5cm}}%

• There seems to be a problem with appendix chapters when I use this and \appendix with appendixprefix=true for my documentclass, do you happen to know how to fix this? – voiDnyx Apr 12 '18 at 13:36
• @voiDnyx See my updated answer. If it does not solve your issue, then please ask a follow up question and explain what the desired layout for chapters in appendix is. Maybe \chapterlineswithprefixformat must be redefined too. – esdd Apr 13 '18 at 9:50