# Customizing chapter and section style (scrbook)

I have found a very cool custom style for chapter and section headings (It is from Customizing Chapter style in scrbook):

\documentclass[
11pt,
pagesize=auto,
version=last,
chapterprefix=true
]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}
\usepackage{charter}

\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{myblueii}{RGB}{131,197,231}

\newcommand\ChapterFont{\usefont{T1}{qhv}{b}{n}\selectfont\huge}
\newcommand\SectionFont{\usefont{T1}{qhv}{b}{n}\selectfont}

\titleformat{\chapter}[display]
{\normalfont\ChapterFont\huge\color{myblueii}}
{}
{0pt}
{\parbox[b]{70pt}{\mbox{}}%
\parbox[b]{50pt}{\colorbox{mybluei}{%
\parbox[b][60pt][t]{45pt}{\centering%
\color{white}%
{\itshape\rmfamily\small\chaptertitlename}%
\vfill{\fontsize{50}{120}\selectfont\thechapter}%
}%
}%
}\hspace{15pt}%
\parbox[b]{\dimexpr\textwidth-150pt}{%
\raggedright\scshape#1\vskip6pt%
}%
}

\titleformat{name=\chapter,numberless}[display]
{\normalfont\ChapterFont\huge\color{myblueii}}
{}
{0pt}
{\parbox[b]{70pt}{\mbox{}}%
\hspace{15pt}%
\parbox[b]{\dimexpr\textwidth-150pt}{%
\raggedright\scshape#1\vskip6pt%
}%
}

\titleformat{\section}
{\normalfont\small\sffamily\SectionFont\color{myblueii}}
{\colorbox{mybluei}{%
\parbox[c][16pt][c]{40pt}{%
\centering\textcolor{white}{\SectionFont\Large\rmfamily\thesection}%
}%
}%
}
{1em}
{#1}
[\vspace{-1.2\baselineskip}%
\color{myblueii}\hspace*{\dimexpr40pt+2\fboxsep\relax}%
\rule{\dimexpr\textwidth-40pt-2\fboxsep\relax}{1pt}%
]

\begin{document}

\chapter{Preliminaries}
\section{Test section}

\end{document}


I have two problems with it.

First, I want the chapter heading a bit bigger and the name of the section heading should also be bigger. How can this be done?

Second, I want the chapter heading to be not indented, i.e it should be left centered.

Edit: I have now tried out the approach by esdd for not breaking the KOMA-class and I have now several problems:

1. In the list of contents the chapter titles are in blue but the section titles are in black. Is it possible to have also the chapter titles in black?

2. Is it possible to make the line a bit lower as in the example of Benjaming? For me this lower line looks better. Please see the image below.

3. Benjamin also made subsubsection title without a numbering (because otherwise it is too much styling). Please also see the image below. Is this also possible?

Edit 2: Now everything is almost perfect except the line below the title. In your example it looks great but if I use it in my document the line appears lower. I tried different things but I can't find the solution. Do you see where the problem is? I also don't know if my template is perfect or if there are other mistakes. Please see below the example.

main.tex

\documentclass[a4paper,twoside,12pt,chapterprefix=false]{scrbook}

\usepackage{amsmath,amssymb,amsthm}
\usepackage[footnotesize,sl,SL,hang,tight]{subfigure}
\usepackage{longtable}
\usepackage[font={small,sl},hang,labelfont=bf]{caption}
\usepackage{booktabs}

\ifpdfoutput{%
\usepackage[pdftex]{graphicx}
\usepackage[]{pdfpages}
}{%
\usepackage{graphicx}
}
\usepackage{rotating}

\usepackage{scrlayer-scrpage}

% **** Defining chapter style start ****

\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{charter}

\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{myblueii}{RGB}{131,197,231}

\newkomafont{chapternumber}{\fontsize{50}{120}\selectfont\color{white}}
\newkomafont{chaptername}{\itshape\rmfamily\small\color{white}}
\addtokomafont{chapterentry}{\normalcolor}% entrys in tableofcontents not blue

\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\rmfamily\color{white}}

\newkomafont{subsectionnumber}{\fontsize{16pt}{16pt}\selectfont\rmfamily\color{white}}

\setcounter{secnumdepth}{\subsectionnumdepth}% subsubsection and lower unnumbered

\renewcommand\chapterformat{%
\raisebox{-6pt}{\colorbox{mybluei}{%
\parbox[b][60pt]{45pt}{\centering%
{\usekomafont{chaptername}{\chaptername}}%
\vfill{\usekomafont{chapternumber}{\thechapter\autodot}}%
\vspace{6pt}%
}}}\enskip}

\renewcommand\sectionformat{%
\setlength\fboxsep{5pt}%
\colorbox{mybluei}{%
\parbox{40pt}{\centering\usekomafont{sectionnumber}{\thesection\autodot}}}%
}

\renewcommand\subsectionformat{%
\setlength\fboxsep{5pt}%
\colorbox{mybluei}{%
\parbox{60pt}{\centering\usekomafont{subsectionnumber}{\thesubsection\autodot}}}%
}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hspace*{#2}#3}{#4}%
\ifstr{#1}{section}{%
\par\nobreak%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{50pt}\rule[\dp\strutbox]{\dimexpr\textwidth-50pt}{1pt}}%
}{}%
\ifstr{#1}{subsection}{%
\par\nobreak%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{70pt}\rule[\dp\strutbox]{\dimexpr\textwidth-70pt}{1pt}}%
}{}%
}
\makeatother

% **** Defining chapter style end ****

% Define an own layer page style for the title page
\DeclareNewLayer[
background,
height=1.5cm,
contents={%
\includegraphics[height=1.5cm]{figures/ETH_logo.pdf}%
\hfill%
\includegraphics[height=1.4cm]{figures/CGL_logo.pdf}%
}

\usepackage{times}
\usepackage{helvet}
\usepackage[T1]{fontenc}

\ifpdfoutput{%
\usepackage[pdftex,
bookmarks,
bookmarksopen=true,
bookmarksnumbered=true,
pdfauthor={Rafael Wampfler},
pdftitle={Engagement Detector: Modelling engagement dynamics in virtual environments},
pdfsubject={The report of the master thesis about the modelling engagement dynamics in virtual environments.},
pdfkeywords={machine learning, engagement dynamics, classification, virtual environments, calcularis, learning, minecraft},
citecolor=black,
filecolor=black,
urlcolor=black,
anchorcolor=black,
pageanchor=true,
plainpages=false,
citebordercolor=red,
urlbordercolor=red,
pdfpagelabels=true]{hyperref}
}{}

\ifpdfoutput{%
\pdfcompresslevel=9
\pdfoutput=1
\DeclareGraphicsExtensions{.pdf,.png}
}{}

\bibliographystyle{alpha}

\topmargin -0.5in
\textheight 9.3in
\textwidth 6.3in
\oddsidemargin 0.18in
\evensidemargin -0.22in
\parskip 0.1in
\parindent 0in

\renewcommand{\arraystretch}{1.5}
\renewcommand{\baselinestretch}{1}

\begin{document}

%
\input{studchapter}
\newpagestyle{mychapterpagestyle}{{\protect\mychpstyleintl}{\protect\mychpstyleintl}}{}
\newpagestyle{myappendixpagestyle}{{\protect\mychpstyleintl}{\protect\mychpstyleintl}}{}
%%

\hypersetup{pageanchor=false}

\hypersetup{pageanchor=true}
\pagenumbering{roman}
\setcounter{page}{1}

%\include{abstract}

%\include{acknowledgment}

\tableofcontents
\cleardoublepage

\listoffigures
\cleardoublepage

\listoftables
\cleardoublepage

\pagenumbering{arabic}
\renewcommand*{\chapterpagestyle}{mychapterpagestyle}
\renewcommand*{\chapterformat}{} % show chapter titles only (no numbers)

% ---- MAIN PART ----

\chapter{Chapter Title}
\section{Section Title}
\blindtext
\blindtext
\subsection{Subsection Title}
\blindtext
\subsubsection{Subsubsection Title}
\blindtext
\blinddocument

% ---- END MAIN PART ----

\appendix
\clearpage
\renewcommand*{\chapterpagestyle}{myappendixpagestyle}

%\include{appendix}

\clearpage
\renewcommand*{\chapterpagestyle}{empty}

\bibliography{references}

\end{document}


studchapter.tex

\renewcommand*{\chapterheadstartvskip}{\vspace*{215pt}}

\def\mychpstyleintl{%
{\noindent\setlength{\tabcolsep}{0pt}\setlength{\arrayrulewidth}{2pt}%
\begin{tabular}{c}
\\[100pt]
\begin{tabular}{lr}
\begin{tabular}{p{0.6\linewidth}}
\\
\end{tabular}
&
\begin{tabular}{p{0.4\linewidth}}
\rightline{{%
\sffamily%
\fontseries{bx}%
\fontshape{n}%
\selectfont
\thechapter}}
\end{tabular}
\end{tabular}\\[300pt]
\end{tabular}
}}


• This really breaks the KOMA interface so you end up with competing things trying to format the same document elements. I always think that's asking for trouble and confusion....
– cfr
Jan 22, 2016 at 23:54

Here is an example without package titlesec.

\documentclass[numbers=noenddot]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{charter}

\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{myblueii}{RGB}{131,197,231}

\newkomafont{chapternumber}{\fontsize{50}{120}\selectfont\color{white}}
\newkomafont{chaptername}{\itshape\rmfamily\small\color{white}}

\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\rmfamily\color{white}}

\newkomafont{subsectionnumber}{\fontsize{16pt}{16pt}\selectfont\rmfamily\color{white}}

\renewcommand\chapterformat{%
\raisebox{-6pt}{\colorbox{mybluei}{%
\parbox[b][60pt]{45pt}{\centering%
{\usekomafont{chaptername}{\chapapp}}%
\vfill{\usekomafont{chapternumber}{\thechapter\autodot}}%
\vspace{6pt}%
}}}\enskip}

\renewcommand\sectionformat{%
\setlength\fboxsep{5pt}%
\raisebox{-4pt}{\colorbox{mybluei}{%
\enskip\usekomafont{sectionnumber}{\thesection\autodot}\enskip}%
}}

\renewcommand\subsectionformat{%
\setlength\fboxsep{5pt}%
\raisebox{-4pt}{\colorbox{mybluei}{%
\enskip\usekomafont{subsectionnumber}{\thesubsection\autodot}\enskip}%
}}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
\makebox[0pt][l]{\rule[-5pt]{\textwidth}{1pt}}%
\@hangfrom{#3}{#4}%
}
\makeatother

\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\chapter{Chapter Title}
\section{Section Title}
\blindtext
\blindtext
\subsection{Subsection Title}
\blindtext
\subsubsection{Subsubsection Title}
\blindtext
\blinddocument
\end{document}


Update because of updates in the question:

\addtokomafont{chapterentry}{\normalcolor}% entrys in tableofcontents not blue


If all subsections should be unnumbered use

\setcounter{secnumdepth}{\subsectionnumdepth}% subsubsection and lower unnumbered


And here is an example with lower rules:

\documentclass[numbers=noenddot]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{charter}

\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{myblueii}{RGB}{131,197,231}

\newkomafont{chapternumber}{\fontsize{50}{120}\selectfont\color{white}}
\newkomafont{chaptername}{\itshape\rmfamily\small\color{white}}
\addtokomafont{chapterentry}{\normalcolor}% entrys in tableofcontents not blue

\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\rmfamily\color{white}}

\newkomafont{subsectionnumber}{\fontsize{16pt}{16pt}\selectfont\rmfamily\color{white}}

\setcounter{secnumdepth}{\subsectionnumdepth}% subsubsection and lower unnumbered

\renewcommand\chapterformat{%
\raisebox{-6pt}{\colorbox{mybluei}{%
\parbox[b][60pt]{45pt}{\centering%
{\usekomafont{chaptername}{\chapapp}}%
\vfill{\usekomafont{chapternumber}{\thechapter\autodot}}%
\vspace{6pt}%
}}}\enskip}

\renewcommand\sectionformat{%
\setlength\fboxsep{5pt}%
\colorbox{mybluei}{%
\parbox{40pt}{\centering\usekomafont{sectionnumber}{\thesection\autodot}}}%
}

\renewcommand\subsectionformat{%
\setlength\fboxsep{5pt}%
\colorbox{mybluei}{%
\parbox{60pt}{\centering\usekomafont{subsectionnumber}{\thesubsection\autodot}}}%
}

\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hspace*{#2}#3}{#4}%
\ifstr{#1}{section}{%
\par\nobreak%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{50pt}\rule[\dp\strutbox]{\dimexpr\textwidth-50pt}{1pt}}%
}{}%
\ifstr{#1}{subsection}{%
\par\nobreak%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{70pt}\rule[\dp\strutbox]{\dimexpr\textwidth-70pt}{1pt}}%
}{}%
}
\makeatother

\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\chapter{Chapter Title}
\section{Section Title}
\blindtext
\blindtext
\subsection{Subsection Title}
\blindtext
\subsubsection{Subsubsection Title}
\blindtext
\blinddocument
\end{document}


Update 2 because of a second update in the question

You are using a \parskip so \par inserts vertically space that must be removed:

\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hspace*{#2}#3}{#4}%
\ifstr{#1}{section}{%
\parskip\z@% <- added, deactivates the parskip locally
\par\nobreak
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{50pt}\rule[\dp\strutbox]{\dimexpr\textwidth-50pt}{1pt}}%
}{}%
\ifstr{#1}{subsection}{%
\parskip\z@% <- added, deactivates the parskip locally
\par\nobreak
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{70pt}\rule[\dp\strutbox]{\dimexpr\textwidth-70pt}{1pt}}%
}{}%
}
\makeatother


Do not set \parskip manually! Use the KOMA-Script option parskip=half- instead. There are other values for this option like half, half+, half* and the same with full. For further explanations see the scrguien.pdf (KOMA-Script documentation).

I would suggest to use package geometry to set the page margins.

To get an entry for the lists and the bibliography in the table of contents use the KOMA-Script options listof=totoc and bibilography=totoc instead of \addcontentsline{toc}{chapter}{...}.

You redefine \chapterformat twice. Decide which one you want to use and remove the other.

The header of your new defined mychapterpagestyle is outside the paper.

• Very nice, one of the better layouts, great! Jan 22, 2016 at 20:49
• Thank you for the example. What is the difference when not using titlesec? It looks very similar to the solution of Benjamin. Jan 23, 2016 at 9:59
• It is not recommended to use titlesec together with a KOMA-Script class. You will get warnings regarding this from both the KOMA-Script class and titlesec. Note that Markus has some effort to ensure that KOMA-Script documents using titlesec will not break.
– esdd
Jan 23, 2016 at 10:23
• @esdd I have tried out your approach and have some questions. Please see my edited original post. Thank you very much. Jan 23, 2016 at 22:16
• @machinery See my updated answer.
– esdd
Jan 24, 2016 at 3:19

\documentclass[
11pt,
pagesize=auto,
version=last,
chapterprefix=true
]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}
\usepackage{charter}

\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{myblueii}{RGB}{131,197,231}

\newcommand\ChapterFont{\usefont{T1}{qhv}{b}{n}\selectfont}
\newcommand\SectionFont{\usefont{T1}{qhv}{b}{n}\selectfont}

\newlength{\chapterfontsize}
\setlength{\chapterfontsize}{30pt}
\newlength{\sectionfontsize}
\setlength{\sectionfontsize}{14pt}
\newlength{\subsectionfontsize}
\setlength{\subsectionfontsize}{12pt}

\titleformat{\chapter}[display]
{\normalfont\ChapterFont\fontsize{\chapterfontsize}{\chapterfontsize}\color{myblueii}}%
{}
{0pt}
{% <-- REMOVED INDENTATION
\parbox[b]{50pt}{\colorbox{mybluei}{%
\parbox[b][60pt][t]{45pt}{\centering%
\color{white}%
{\itshape\rmfamily\small\chaptertitlename}%
\vfill{\fontsize{50}{120}\selectfont\thechapter}%
\vspace{6pt}%
}%
}%
}\hspace{15pt}%
\parbox[b]{\dimexpr\textwidth-150pt}{%
\raggedright\scshape#1\vskip6pt%
}%
}

\titleformat{name=\chapter,numberless}[display]
{\normalfont\ChapterFont\fontsize{\chapterfontsize}{\chapterfontsize}\color{myblueii}}
{}
{0pt}
{{\mbox{}}%
\parbox[b]{\dimexpr\textwidth-150pt}{%
\raggedright\scshape#1\vskip6pt%
}%
}

\titleformat{\section}
{\normalfont\fontsize{\sectionfontsize}{\sectionfontsize}\sffamily\SectionFont\color{myblueii}} %
{\colorbox{mybluei}{%
\parbox[c][1.2\sectionfontsize][c]{2\sectionfontsize}{%
\centering\textcolor{white}{\SectionFont\fontsize{1.2\sectionfontsize}{1.2\sectionfontsize}\rmfamily\thesection}%
}%
}%
}
{1em}
{#1}
[\vspace{-1\baselineskip}%
\color{myblueii}\hspace*{\dimexpr2\sectionfontsize+2\fboxsep\relax}%
\rule{\dimexpr\textwidth-2\sectionfontsize-2\fboxsep\relax}{1pt}%
]

\titleformat{name=\section,numberless}[display]
{\normalfont\fontsize{\sectionfontsize}{\sectionfontsize}\sffamily\SectionFont\color{myblueii}}
{}
{0pt}
{{\mbox{}}%
\parbox[b]{\dimexpr\textwidth-150pt}{%
\raggedright#1\vskip6pt%
}%
}
[\vspace{-1\baselineskip}\color{myblueii}\rule{\textwidth}{1pt}]

\titleformat{\subsection}
{\normalfont\fontsize{\subsectionfontsize}{\subsectionfontsize}\sffamily\SectionFont\color{myblueii}} %
{\colorbox{mybluei}{%
\parbox[c][1.2\subsectionfontsize][c]{3\subsectionfontsize}{%
\centering\textcolor{white}{\SectionFont\fontsize{1.2\subsectionfontsize}{1.2\subsectionfontsize}\rmfamily\thesubsection}%
}%
}%
}
{1em}
{#1}
[\vspace{-1\baselineskip}%
\color{myblueii}\hspace*{\dimexpr3\subsectionfontsize+2\fboxsep\relax}%
\rule{\dimexpr\textwidth-3\subsectionfontsize-2\fboxsep\relax}{1pt}%
]

\titleformat{\subsubsection}
{\normalfont\fontsize{\subsectionfontsize}{1.2\subsectionfontsize}\sffamily\SectionFont\color{myblueii}}
{}
{1em}
{#1}

\begin{document}

\chapter*{Abstract}
\chapter{Chapter Title}
\section{Section Title}
\subsection{Subsection Title}
\subsubsection{Subsubsection Title}

\end{document}

• Thank you very much, it worked very well. I have only a couple of things. 1. The chapter heading is still a bit too small (especially the box) 2. The box of the section heading (with the section number in it) is now a bit too small compared to the section title. 3. The abstract, acknowledgments, content, list of figures and list of tables headers are indented but I would prefer to have them not indented. Jan 21, 2016 at 23:22
• Ok, so I added two lengths where you can set the font size easily by yourself. The section boxes should scale quite well with the change of fantasize. What do you mean with your third remark. Can you update your MWE? Jan 21, 2016 at 23:43
• Thank you so much, it looks great. What do you mean with MWE? With the third remark I mean the following: At the beginning of my document I have the abstract, acknowledgment, list of content, list of figures and list of tables. Each of this has a heading, i.e. a title, for example "abstract". The problem now is that this titles are all not left aligned, i.e. they are indented but I would like it to have left aligned. This only happens when adding this special chapter / section layout. Jan 22, 2016 at 9:41
• There is just another last problem: subsections and subsusetions are not in the special new layout. How can I made this too? Jan 22, 2016 at 9:44
• The MWE is the Minimal Working Example you provided. So your original LaTeX Code. Here is some more information on how to write a good MWE: [meta.tex.stackexchange.com/questions/228/…. I asked to extend yours as there is no abstract environment for example in the scrbook class. So I wanted to know how you added it. Nevertheless I think I understand what you mean. I updated my code. Jan 22, 2016 at 10:20