4

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. enter image description here 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. enter image description here

  • 1
    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
  • Please make sure your code compiles before uploading it! – cfr Dec 9 '15 at 1:42
5

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[
  headings=chapterprefix
]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}

\addtokomafont{chapterprefix}{\Large}
\addtokomafont{disposition}{\rmfamily}

\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
\addchap{Test the second}
\blindtext
\end{document}

enter image description here

enter image description here


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

enter image description here

enter image description here

Code:

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

\addtokomafont{chapterprefix}{\Large}
\addtokomafont{disposition}{\rmfamily}

\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
\addchap{Test the second}
\blindtext
\end{document}
1

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

Something like this?

ruled chapter title

\documentclass[chapterprefix]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[scaled]{beramono}
% see manual esp. chapter 21
\makeatletter
\renewcommand*{\chapterheadstartvskip}{\vspace{\@tempskipa}\hfill}
\renewcommand*{\chapterheadmidvskip}{\vskip.5\@tempskipa\par\nobreak\noindent\rule{\textwidth}{1pt}\vskip.5\@tempskipa\par\nobreak}
\renewcommand*{\chapterheadendvskip}{\vskip.25\@tempskipa\par\nobreak\noindent\rule{\textwidth}{1pt}}
\makeatother
\setkomafont{chapter}{\bfseries\huge}
\setkomafont{chapterprefix}{\bfseries\Large}
\addtokomafont{disposition}{\rmfamily}
\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.