如何仅在第一章页面上禁用页眉分隔线?

如何仅在第一章页面上禁用页眉分隔线?

我正在使用scrbook带有页面样式的文档scrlayer-scrpage。文档范围的页面样式scrheadings经过了一些自定义修改,例如,我将页码从页脚移到了页眉并添加了分隔线。这是我的最小工作示例。

\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}

但是,我希望第一章页面的分隔线宽度(0.0pt / 不可见)和所有其他页面的分隔线宽度(0.5pt)不同。

命令的更新chapter会以某种方式将所有后续标题分隔线宽度重置为 0。我该如何避免这种情况?

答案1

您不应该重新定义\chapter以更改页面样式和线宽。而应该只配置清楚的页面样式:

\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}

如果确实需要更改章节页面的页面样式,请重新定义\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}

相关内容