# titlesec is not properly working with KOMA-Script

I am new to latex and I am using titlesec for formatting the chapter headings with titlesec.

\usepackage{titlesec}

\titleformat{\chapter}[display]
{\bfseries\huge}
{\filleft\Large\chaptertitlename~\thechapter}
{1ex}
{\titlerule\vspace{1.5ex}\filright}
[\vspace{1ex}\titlerule]


but I am not getting my chapter heading properly. I just get plain text.

I am also getting this warning. Is this a reason for it?

I have a created small MME

\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
\usepackage{graphicx}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\bfseries\huge}
{\filleft\Large\chaptertitlename~\thechapter}
{1ex}
{\titlerule\vspace{1.5ex}\filright}
[\vspace{1ex}\titlerule]
\begin{document}
\chapter{Introduction}
\label{ch:Introduction}
\end{document}


I would like to have following result without package titlesec.

• You shouldn't use titlesec with koma classes. They are quite incompatible with each other and this is noted in the koma manual. Koma classes have functionalities to format title embedded. – ArTourter Dec 8 '15 at 22:01
• Welcome! As @ArTourter suggests, this combination is not recommended. You don't even need to read the documentation. The warning says exactly the same. But whether or not you follow the class's recommendation, we would need more information - in the form of a Minimum Working Example (MWE) - to help effectively. This should be code for the smallest document you can create which illustrates the problem. I.e. \documentclass... \end{document} such that, when we copy-paste-compile, we can reproduce the problem you want help with. – cfr Dec 8 '15 at 22:22
• i have created small MME – Koustubh Dec 8 '15 at 23:05

Do not use titlesec together with a KOMA-Script class.

With KOMA-Version 3.19 or newer it is possible to insert title rules by redefining \chapterlineswithprefixformat:

\newcommand\titlerule[1][.4pt]{\rule[.5\baselineskip]{\textwidth}{#1}}

\renewcommand\chapterlineswithprefixformat[3]{%
{\raggedleft#2}\nobreak%
\ifstr{#2}{}{\kern-.5\baselineskip}{}%
\titlerule\\*%
\kern-.5ex%
#3\par\nobreak%
\kern1.75ex%
\titlerule%
}


To change the skips before and after the chapter title and also between the chapterprefix and the title you can use RedeclareSectionCommand.

\documentclass[
]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}

\RedeclareSectionCommand[%
beforeskip=\dimexpr4.6\baselineskip+\parskip\relax,
innerskip=0pt,
afterskip=1.5\baselineskip plus .115\baselineskip minus .192\baselineskip
]{chapter}

\newcommand\titlerule[1][.4pt]{\rule[.5\baselineskip]{\textwidth}{#1}}

\renewcommand\chapterlineswithprefixformat[3]{%
{\raggedleft#2}\nobreak%
\ifstr{#2}{}{\kern-.5\baselineskip}{}%
\titlerule\\*%
\kern-.5ex%
#3\par\nobreak%
\kern1.75ex%
\titlerule%
}

\usepackage{blindtext}% only for dummy text
\begin{document}
\chapter{Test}
\blindtext
\blindtext
\end{document}


If the lines should be also there without option headings=chapterprefix add a redefinition of chapterlinesformat:

\makeatletter
\renewcommand\chapterlinesformat[3]{%
\titlerule\\*%
\kern-.5ex%
\@hangfrom{#2}{#3}\par\nobreak%
\kern1.75ex%
\titlerule%
}
\makeatother


Code:

\documentclass[
]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}

\RedeclareSectionCommand[%
beforeskip=\dimexpr4.6\baselineskip+\parskip\relax,
innerskip=0pt,
afterskip=1.5\baselineskip plus .115\baselineskip minus .192\baselineskip
]{chapter}

\newcommand\titlerule[1][.4pt]{\rule[.5\baselineskip]{\textwidth}{#1}}

\renewcommand\chapterlineswithprefixformat[3]{%
{\raggedleft#2}\nobreak%
\ifstr{#2}{}{\kern-.5\baselineskip}{}%
\titlerule\\*%
\kern-.5ex%
#3\par\nobreak%
\kern1.75ex%
\titlerule%
}

\makeatletter
\renewcommand\chapterlinesformat[3]{%
\titlerule\\*%
\kern-.5ex%
\@hangfrom{#2}{#3}\par\nobreak%
\kern1.75ex%
\titlerule%
}
\makeatother

\usepackage{blindtext}% only for dummy text
\begin{document}
\chapter{Test}
\blindtext
\blindtext
\end{document}


Probably not the best way to do it, but I hope somebody who knows the class will correct me.

Something like this?

\documentclass[chapterprefix]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
% see manual esp. chapter 21
\makeatletter
\makeatother
\setkomafont{chapter}{\bfseries\huge}
\setkomafont{chapterprefix}{\bfseries\Large}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
\raggedchapter
\@hangfrom{#2}#3%
}
\makeatother
\renewcommand{\chapterlineswithprefixformat}[3]{%
\raggedleft
#2%
\raggedright
#3%
}

\begin{document}
\chapter{Introduction}
\label{ch:Introduction}
\end{document}