I want to add one horizontal line above and one below the chapter-entry as well.
Before using the scrbook
-class, I used this simple solution made by titlesec
-package:
\newpagestyle{headrules}{
\headrule
% for twosided layout, use:
\sethead[\thepage][\chaptertitle][] % even pages (left side of book)
{\chaptertitle}{\sectiontitle}{\thepage} % odd pages (right side of book)
% for onesided layout, use:
% \sethead{\thechapter. \chaptertitle}{}{\thepage} % in this case, the document only has odd pages
}
Working minimum example:
\documentclass{book}
\usepackage[english]{babel}
\usepackage[automark]{scrpage2}
\usepackage[pagestyles]{titlesec}
\usepackage{blindtext}
\titleformat{\chapter}[display]{\fontfamily{pag}\Large\bfseries}{\titlerule[4pt]\chaptertitlename\ \thechapter}{5pt}{\large}[{\titlerule[2pt]}]
\titleformat{\section}{\fontfamily{pag}\normalsize\bfseries}{\thesection}{5pt}{\normalsize}
\titleformat{\subsection}{\fontfamily{pag}\normalsize\bfseries}{\thesubsection}{5pt}{\normalsize}
\titlespacing*{\chapter}{0pt}{30pt}{20pt}
\titlespacing*{\section}{0pt}{20pt}{10pt}
\titlespacing*{\subsection}{0pt}{20pt}{5pt}
\newpagestyle{headrules}{
\headrule
% for twosided layout, use:
\sethead[\thepage][\chaptertitle][] % even pages (left side of book)
{\chaptertitle}{\sectiontitle}{\thepage} % odd pages (right side of book)
% for onesided layout, use:
% \sethead{\thechapter. \chaptertitle}{}{\thepage} % in this case, the document only has odd pages
}
\setlength{\headheight}{1.1\baselineskip} % adjusting the height of head
\pagestyle{headrules} % use this style instead of \pagestyle{plain}
\begin{document}
\blinddocument
\end{document}
Screenshot:
So, the question now is: How can I solve this without using the titlesec
-package anymore? Using titlesec
together with a KOMA-class is not recommended, and I prefer to use the scrbook
-class instead of book
because of those many great advantages (for example addchap
and others)…
Do I have to change the pagestyle plain
-format for this?
Thank you very much for your help!
The following solution from clemens for separating \chapters
and \addchaps
seems to make sense, but it doesn't work in the following minimal-example (don't know why):
\documentclass[chapterprefix=true]{scrbook}
\renewcommand*\chapterheadstartvskip{%
\ifnumbered{chapter}
{\noindent\rule{\linewidth}{4pt}\par\vspace*{-4pt}}
{}%
}
\renewcommand*\chapterheadendvskip{%
\ifnumbered{chapter}
{\vspace*{-4pt}\noindent\rule{\linewidth}{2pt}\par\vspace{\baselineskip}}
{}%
}
\begin{document}
\chapter{Experimental chapter-entry}
\addchap{Experimental addchap-entry}
\end{document}
It doesn't matter if there's a numbered \chapter
or an unnumbered \addchap
– either the selected line is existent or absent in both selectors…
Is there any mistake in my line of thought?
Solution: Upgrading to KOMA-Script v3.18 brought the solution for me, too! Thank you very much clemens and all the others who were helping me!
Thanks a lot for your patient help!
Best Answer
Update
With KOMA-Script Version 3.19 or newer there is another possibility: you can redefine the new command
\chapterlineswithprefixformat
to insert the lines:MWE:
If this should also work with option
chapterprefixline=false
add the following lines to the preamble:Original answer
If the line above the chapter heading should only be inserted if the
chapterprefix
is written you could insert this line in\chapterformat
. This works also for\chapter*
and\addchap*
.