scrlayer-scrpage:定义 \newpairofpagestyles 时切换页面样式层

scrlayer-scrpage:定义 \newpairofpagestyles 时切换页面样式层

来自之前的一个问题(scrlayer-scrpage:使标题线相交,但不删除文本),我得到了 MWE 中包含的关于如何在 scrlayer-scrpage 的页面样式中切换图层的代码。但是,当我定义一对新的页面样式时,图层切换被撤消。我如何再次切换图层?(MWE 包含我的一次尝试,在 之后立即进行切换\clearscrheadfoot

梅威瑟:

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

\usepackage{xcolor}

%%%---header/footer
\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}}~%
}}

\newpairofpagestyles{MyAppend}{%
    \clearscrheadfoot%
    \RemoveLayersFromPageStyle{scrheadings}{scrheadings.head.below.line}
    \AddLayersAtBeginOfPageStyle{scrheadings}{scrheadings.head.below.line}
    \ohead*{\Ifstr{\headmark}{}{}{%
            \raisebox{-.75\ht\strutbox}[0pt][0pt]{\colorbox{green!20}{\strut Custom Text}}~%
    }}
    \ofoot*{\pagemark} 
}

\usepackage{lipsum}

\begin{document}

\chapter{First}

\lipsum[1-14]

\newpage

\pagestyle{MyAppend}

\lipsum[41-50]

\end{document}

在此处输入图片描述

答案1

如果您想要切换样式的图层,MyAppend则必须使用此样式的名称和此样式的图层:

\RemoveLayersFromPageStyle{MyAppend}{MyAppend.head.below.line}
\AddLayersAtBeginOfPageStyle{MyAppend}{MyAppend.head.below.line}

例子:

\documentclass[11pt,headsepline,twoside,chapterprefix=true]{scrreprt}
\usepackage{xcolor}
%%%---header/footer
\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}}

\ohead{\Ifstr{\headmark}{}{}{%
  \ifodd\value{page}\else~\fi
  \raisebox{-.75\ht\strutbox}[0pt][0pt]{\colorbox{gray!20}{\strut\headmark}}%
  \ifodd\value{page}~\fi
}}% changed


\newpairofpagestyles[scrheadings]{MyAppend}{%
  \clearpairofpagestyles% <- changed
  \RemoveLayersFromPageStyle{MyAppend}{MyAppend.head.below.line}% <- changed!
  \AddLayersAtBeginOfPageStyle{MyAppend}{MyAppend.head.below.line}% <- changed!
  \ohead*{%
    \ifodd\value{page}\else~\fi
    \raisebox{-.75\ht\strutbox}[0pt][0pt]{\colorbox{green!20}{\strut Custom Text}}%
    \ifodd\value{page}~\fi
  }% changed
  \ofoot*{\pagemark}
}

\usepackage{lipsum}
\begin{document}
\chapter{First}
\lipsum[1-14]
\newpage
\pagestyle{MyAppend}
\lipsum[41-50]
\end{document}

在此处输入图片描述

相关内容