# Replace titlesec-chapter style with KOMA

I have built a very nice chapter style with titlesec:

Unfortunately there's a warning for the use together with "scrbook". That's why I want to replace titlesec with KOMA.

   \usepackage{titlesec}
%CHAPTER
\titleformat{\chapter}[display] %shape
{\usefont{T1}{lmss}{b}{n}\filleft\huge\bfseries}    %format
{\makebox[\linewidth][r]{\raisebox{103pt}[0pt][0pt]{\textcolor{gray!25}{\usefont{T1}{lmss}{b}{n}\fontsize{80pt}{95pt}\selectfont\thechapter}}}
{}  %default would be huge
}   %label
{-14ex} %sep
{}  %before-code
[\vspace{0.5ex}\titlerule]

\titleformat{name=\chapter,numberless}[display]
{\usefont{T1}{lmss}{b}{n}\filleft\huge\bfseries}    %format
%{\makebox[25pt][l]{\raisebox{100pt}[0pt][0pt]{\textcolor{gray!25}{\usefont{T1}{lmss}{b}{n}\fontsize{80pt}{80pt}\selectfont\thechapter}}}
{\makebox[10pt][l]{\raisebox{10pt}[0pt][0pt]{\textcolor{gray!25}{\usefont{T1}{lmss}{b}{n}\fontsize{10pt}{12pt}\selectfont}}}
{}  %default would be huge
}   %label
{-16.8ex}   %sep
{}  %before-code
[\vspace{1ex}\titlerule]

\titlespacing{\chapter}
{0pc}{*30}{*5}[0pc] %Abstand zum linken Rand |Abstand zum oberen Text | Abstand zum unteren Text | Abstand zum rechten Rand

%SECTION
\titleformat{\section}
{\usefont{T1}{lmss}{b}{n}\filright\Large}
{\thesection}{1em}{}

\titlespacing{\section}
{0pc}{*0}{*-1}[0pc]

\setcounter{secnumdepth}{3}

%SUBSECTION
\titleformat{\subsection}
{\usefont{T1}{lmss}{b}{n}\large}
{\thesubsection}{1em}{}

\titlespacing{\subsection}
{0pc}{*0}{*-1}[0pc]


Also I want the appendix to have the same look like a normal chapter.

The other chapters without a number should look like this:

The height above the title for a chapter without number and the height above the chapter numer for a chapter with number should be the same.

A lot of questions... -.- I hope somebody will help me to solve this as my KOMA knowledge is very poor -.-

Thanks!

After some research, I ended up with

  \renewcommand*\raggedchapter{\raggedleft}

\newcommand\titlerule[1][.4pt]{\rule[.5\baselineskip]{\textwidth}{#1}}
\renewcommand*{\chapterformat}{%
\makebox[\width][l]{\scalebox{1}{{\nobreakspace}}%
\scalebox{4}{\textcolor{gray!25}\thechapter\autodot}\enskip}
}


It seems to work, but unfortunately some things are missing:

• the number of the chapter is not completely on the right hand side
• how do I change the space between the number, the name and the line?
• The height above the title for a chapter without number and the height above the chapter numer for a chapter with number is not the same.
• I think it's not going to be as easy in KOMA. What is the warning you get? If it is just a warning but the document compiles fine, why change it? – alexraasch Mar 11 '16 at 14:13
• Maybe related: KOMA-script scrreprt: Chapter Heading Size Customisation. I used something like that to replace the titlesec package for my customized version of the classicthesis package which I use for my thesis. – Stephan Lukasczyk Mar 11 '16 at 14:35
• Thanks for your fast reply. I have edited my post with a little KOMA code. It seems to work, but some things I don't know how to change – Milou Mar 11 '16 at 15:01

Here is suggestion redefining \chapterlineswithprefixformat. This needs KOMA-Script version 3.19a or newer.

\documentclass[chapterprefix]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{lmodern}

\RedeclareSectionCommand[
beforeskip=\dimexpr3.3\baselineskip+1\parskip\relax,
innerskip=0pt,% <- space between chapter number and chapter title
afterskip=1.725\baselineskip plus .115\baselineskip minus .192\baselineskip
]{chapter}
\renewcommand\raggedchapter{\raggedleft}
\renewcommand\chapterformat{{\fontsize{80pt}{80pt}\selectfont\textcolor{gray!25}{\thechapter}}}
\renewcommand\chapterlineswithprefixformat[3]{%
#2#3%
\vspace*{-.5\baselineskip}% <- adjust the space between the chapter and the rule here
\rule{\textwidth}{.4pt}\par\nobreak
}%

\RedeclareSectionCommands[
beforeskip=0pt plus 1ex minus .2ex,
afterskip=1sp plus .2ex
]{section,subsection}
\renewcommand*{\sectionformat}{\thesection\hspace*{1em}}
\renewcommand*{\subsectionformat}{\thesubsection\hspace*{1em}}

\setcounter{secnumdepth}{3}

\usepackage{blindtext}% for dummy text
\begin{document}
\tableofcontents
\blinddocument
\chapter{A long long long long long long long long long chapter title}
\Blindtext
\appendix
\blinddocument
\end{document}


Adjust beforeskip, innerskip and afterskip for the sectioning commands to your needs.

Regarding a comment:

If there should be the same vertical white space between the top of the page and a chapter number or an unnumbered chapter, use a fixed length as beforeskip for chapter

\RedeclareSectionCommand[
beforeskip=3.3\baselineskip,
...
]{chapter}


and insert some additional vertical space before the numbered chapter

\renewcommand\chapterlineswithprefixformat[3]{%
\ifstr{#2}{}{}{\vspace*{1ex}}% <- insert vertical space before numbered chapters
#2#3%
\vspace*{-.5\baselineskip}% <- adjust the space between the chapter and the rule here
\rule{\textwidth}{.4pt}\par\nobreak
}%


or remove some vertical space before unnumbered chapters

\renewcommand\raggedchapter{\raggedleft}
\renewcommand\chapterformat{{\fontsize{80pt}{80pt}\selectfont\textcolor{gray!25}{\thechapter}}}
\renewcommand\chapterlineswithprefixformat[3]{%
\ifstr{#2}{}{\vspace*{-1ex}}{}% <- remove vertical space before unnumbered chapters
#2#3%
\vspace*{-.5\baselineskip}% <- adjust the space between the chapter and the rule here
\rule{\textwidth}{.4pt}\par\nobreak
}%

• Wow, just tried it, and it works perfectly. Thanks a lot! – Milou Mar 15 '16 at 12:25
• Just came up with one last question: how do I change the space between the chapter number and the header? Because still the height above the title for a chapter without number and the height above the chapter number for a chapter with number is not the same. – Milou Mar 15 '16 at 13:08
• @Milou See my updated answer. – esdd Mar 15 '16 at 13:52