scrlayer-scrpage:使标题线相交,但不删除文本

scrlayer-scrpage:使标题线相交,但不删除文本

我想让标题文本与标题线相交。为此,我认为我可以将标题文本放在颜色框中(通常为白色,我在 MWE 中将其设为灰色以使其可见)并将其向下移动。这可行;但是,标题线位于标题文本上方的“层”上,因此会划掉文本。我怎样才能将颜色框“置于”(逐层)标题线的“上方”?或者我需要使用完全不同的方法吗?如果是这样,我该怎么做?

梅威瑟:

\documentclass[11pt,twoside,headsepline,chapterprefix=true]{scrreprt}

\usepackage{xcolor}

%%%---header/footer
\usepackage[manualmark]{scrlayer-scrpage}

%%--"Chapter #" in lehead (only for numbered chapters), chapter name in rohead
\renewcommand*
\chaptermark[1]{%
    \markboth{\ifnumbered{chapter}{\vspace{-14pt} \colorbox{gray!20}{\chaptermarkformat}}{}}{\vspace{-14pt} \colorbox{gray!20}{#1}\hspace{4pt}}%
    }

\AfterTOCHead[toc]{\markboth{}{\contentsname}}

\ofoot[\pagemark]{\pagemark}

\renewcommand\chapterpagestyle{empty} 


\usepackage{lipsum}



\begin{document}

\chapter{First}

\lipsum[1-20]

\chapter{Second}

\lipsum[21-40]

\end{document}

在此处输入图片描述

答案1

原因在于图层页面样式中的图层顺序。您可以使用以下方法列出图层页面样式的所有图层:

\documentclass{scrreprt}
\usepackage{scrlayer-scrpage}
\newcommand*\commaatlist{}
\newcommand*\listpagestylelayers[1]{
  \ForEachLayerOfPageStyle{scrheadings}{%
    \commaatlist##1\gdef\commaatlist{, }}
  \let\commaatlist\relax
}
\begin{document}
\raggedright
\listpagestylelayers{scrheadings}
\end{document}

在此处输入图片描述

您可以删除图层scrheadings.head.below.line并在其他图层之前添加此图层:

\documentclass{scrreprt}
\usepackage{scrlayer-scrpage}
\newcommand*\commaatlist{}
\newcommand*\listpagestylelayers[1]{
  \ForEachLayerOfPageStyle{scrheadings}{%
    \commaatlist##1\gdef\commaatlist{, }}
  \let\commaatlist\relax
}

% reorder the layers -> headsepline behind header text
\RemoveLayersFromPageStyle{scrheadings}{scrheadings.head.below.line}
\AddLayersAtBeginOfPageStyle{scrheadings}{scrheadings.head.below.line}

\begin{document}
\raggedright
\listpagestylelayers{scrheadings}
\end{document}

在此处输入图片描述

然后你可以使用

\documentclass[11pt,twoside,headsepline,chapterprefix=true]{scrreprt}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
%\providecommand*\Ifnumbered{\ifnumbered}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif

\usepackage{xcolor}
\usepackage[manualmark]{scrlayer-scrpage}

% reorder the layers -> headsepline behind header text
\RemoveLayersFromPageStyle{scrheadings}{scrheadings.head.below.line}
\AddLayersAtBeginOfPageStyle{scrheadings}{scrheadings.head.below.line}

%%--"Chapter #" in lehead (only for numbered chapters), chapter name in rohead
\renewcommand*\chaptermark[1]{\markboth{\Ifnumbered{chapter}{\chaptermarkformat}{}}{#1}}
\AfterTOCHead[toc]{\markboth{}{\contentsname}}

\lehead{\Ifstr{\leftmark}{}{}{%
  ~\raisebox{-.75\ht\strutbox}[0pt][0pt]{\colorbox{gray!20}{\strut\leftmark}}%
}}
\rohead{\Ifstr{\rightmark}{}{}{%
  \raisebox{-.75\ht\strutbox}[0pt][0pt]{\colorbox{gray!20}{\strut\rightmark}}~%
}}
%\ofoot*{\pagemark}% default

\renewcommand\chapterpagestyle{empty}

\usepackage{lipsum}% only for dummy text
\begin{document}
\tableofcontents
\minisec{Dummy text to get more ToC pages:}
\lipsum[41-50]

\chapter{First}
\lipsum[1-20]
\chapter{Second}
\lipsum[21-40]
\end{document}

在此处输入图片描述


附加建议在标题中使用不带以下内容的规则headsepline

\documentclass[11pt,twoside,chapterprefix=true,headheight=20pt]{scrreprt}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
%\providecommand*\Ifnumbered{\ifnumbered}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{xcolor}
\usepackage[manualmark]{scrlayer-scrpage}

%%--"Chapter #" in lehead (only for numbered chapters), chapter name in rohead
\renewcommand*\chaptermark[1]{\markboth{\Ifnumbered{chapter}{\chaptermarkformat}{}}{#1}}
\AfterTOCHead[toc]{\markboth{}{\contentsname}}

\clearpairofpagestyles
\lehead{\rule[.75\dp\strutbox]{\linewidth}{.4pt}}
\lohead{\rule[.75\dp\strutbox]{\linewidth}{.4pt}}
\cehead{~\Ifstr{\leftmark}{}{}{\colorbox{gray!20}{\strut\leftmark}}\hfill}
\cohead{\hfill\Ifstr{\rightmark}{}{}{\colorbox{gray!20}{\strut\rightmark}}~}
\ofoot*{\pagemark}% short version of \ofoot[\pagemark]{\pagemark}

\renewcommand\chapterpagestyle{empty}

\usepackage{lipsum}% only for dummy text
\begin{document}
\tableofcontents
Dummy text to get more ToC pages:
\lipsum[41-50]

\chapter{First}
\lipsum[1-20]
\chapter{Second}
\lipsum[21-40]
\end{document}

在此处输入图片描述

相关内容