2

I'm using KOMA-Script and I want to add a line above and below the chapter title. So the upper line should be between the "Chapter" and the title. I did this with

\documentclass{scrbook}
\KOMAoptions{headings=chapterprefix}

\usepackage{etoolbox}
\usepackage{blindtext}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Adding lines above and below the chapter head
%
%%%%%%%% BEFORE HEADING
% \appto\chapterheadstartvskip{%
%   {%
%       \noindent\rule{\linewidth}{1pt}\par%
%   }%
% }   
%%%%%%%% AFTER HEADING
\preto\chapterheadendvskip{%
    {%  
        \noindent\rule{\linewidth}{1pt}\par%
    }%
}
%%%%%%%% BETWEEN LABEL AND HEADING
\renewcommand*{\chapterheadmidvskip}{%
    {%
        \vspace{-.3\baselineskip}%
        \par\noindent%
        \noindent\rule{\linewidth}{1pt}
    }%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\chapter{Test}
\blindtext

\chapter*{Test the second}
\blindtext
\end{document}

The problem is with the \chapter*. It doesn't have the line above. If I include the first part of the code in the example that is now commented, I get the line above \chapter*, but also a third line above \chapter.

Is there anyway to define the \chapterheadstartvskip separately for chapter and chapter*? Or is there anything like \isThisAChapterWithAsteriks

1 Answer 1

5

With KOMA-Script version 3.19a (current on CTAN and in TL2015 und MiKTeX2.9) or newer you can redefine \chapterlineswithprefixformat to insert the line if option headings=chapterprefix is set:

\documentclass[
  headings=chapterprefix
]{scrbook}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif

\newcommand\titlerule[1][1pt]{\rule{\textwidth}{#1}}

\RedeclareSectionCommand[innerskip=0pt]{chapter}

\renewcommand\chapterlineswithprefixformat[3]{%
  #2\nobreak%
  \Ifstr{#2}{}{}{\kern-\dp\strutbox}%
  \titlerule\par\nobreak%
  #3%
  \par\nobreak\titlerule%
}

\usepackage{blindtext}

\begin{document}
\chapter{Test}
\blindtext

\chapter*{Test the second}
\blindtext
\end{document}

enter image description here

enter image description here


If the lines should be also there without headings=chapterprefix you also have to redefine \chapterlinesformat:

\makeatletter
\renewcommand\chapterlinesformat[3]{%
  \titlerule\par\nobreak%
  \@hangfrom{#2}{#3}%
  \par\nobreak\titlerule%
}
\makeatother
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .