[Tex/LaTex] How to disable header separator line on first chapter page only

header-footerkoma-scriptrulesscrbookscrlayer-scrpage

I am using a scrbook document with scrlayer-scrpage for page styling. The document-wide page-style is scrheadings with some custom modifications, e.g., I moved the page numbers from footer to header and added a separator line. Here is my minimal working example.

\documentclass{scrbook}
\usepackage{scrlayer-scrpage}

% default: scrheadings with ruler and empty footer
\pagestyle{scrheadings}
\clearscrheadfoot
\ihead{\headmark}
\ohead{\pagemark}
\cfoot[\pagemark]{}
\setheadsepline{0.5pt} % document-wide (does not work)

% also apply scrheadings to chapter, but without separator
\makeatletter
  \renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
    \thispagestyle{scrheadings}
    \setheadsepline{0.0pt} % only on first chapter page
    \global\@topnum\z@
    \@afterindentfalse
    \secdef\@chapter\@schapter}
\makeatother

\begin{document}
  \chapter{Chapti-po-papti}
     This page should \textsl{not} have a head rule separator.
     \newpage
     This page \textbf{should have} a head rule separator.

\end{document}

However, I want to have different line widths for the separator on the first chapter page (0.0pt / invisible) and on all other pages (0.5pt).

The renewing of the chapter command somehow does reset all following header separator line widths to 0. How can I avoid this?

Best Answer

You should not redefine \chapter to change the page style and line width. Instead of just configure the plain page style:

\documentclass{scrbook}
\usepackage[headsepline=.5pt]{scrlayer-scrpage}

% default: scrheadings with ruler and empty footer
\clearscrheadfoot
\ihead*{\headmark}% use \headmark also for plain pages (not recomended)
\ohead*{\pagemark}% use \pagemark also for plain pages

\begin{document}
  \chapter{Chapti-po-papti}
     This page should \textsl{not} have a head rule separator.
     \newpage
     This page \textbf{should have} a head rule separator.

\end{document}

If you really need to change the page style of chapter pages, redefine \chapterpagestyle:

\documentclass{scrbook}
\usepackage[automark]{scrlayer-scrpage}

\newpairofpagestyles{standardheadings}{%
  \clearpairofpagestyles
  \ihead{\headmark}%
  \ohead{\pagemark}%
  \chead[\pagemark]{}%
  \KOMAoptions{headsepline=.5pt}%
}
\newpairofpagestyles{chapterheadings}{%
  \clearpairofpagestyles
  \ihead{This is not a plain but a chapter page header!}%
  \ohead{\pagemark}%
  \chead[\pagemark]{}%
  \KOMAoptions{headsepline=0pt}%
}
\renewcommand*{\chapterpagestyle}{chapterheadings}
\pagestyle{standardheadings}

\begin{document}
  \chapter{Chapti-po-papti}
     This page should \textsl{not} have a head rule separator.
     \newpage
     This page \textbf{should have} a head rule separator.

\end{document}