[Tex/LaTex] Replace titlesec-chapter style with KOMA

koma-scripttitlesec

I have built a very nice chapter style with titlesec:

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

Can anyone please help me or give me a hint, how to replace this code?

   \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

enter image description here

  \renewcommand*\raggedchapter{\raggedleft}
  \addtokomafont{chapter}{\raggedleft\usefont{T1}{lmss}{b}{n}\huge\bfseries}

\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}
}
\renewcommand*\chapterheadendvskip{\noindent\rule{\linewidth}{0.5pt}\par\vspace{\baselineskip}}

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.

Best Answer

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.

enter image description here


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
}%
Related Question