我已经尝试了很长时间,但仍无法弄清楚如何根据页面是奇数还是偶数来实现不同颜色的头部分隔线。
\documentclass[
11pt,
a4paper,
titlepage,
toc=listof,
toc=bibliography,
headings=standardclasses,
%headings=big,
chapterprefix=true,
numbers=noenddot,
twoside=semi,
]{scrreport}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[automark,headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\lehead{\large{\normalfont{\textsc{\thepage}}}}
\rehead{\large{\normalfont{\textsc{{\headmark}}}}}
\rohead{\large{\normalfont{\textsc{\thepage}}}}
\lohead{\large{\normalfont{\textsc{{\headmark}}}}}
\pagestyle{scrheadings}
\addtokomafont{headsepline}{\color{blue}}
\addtokomafont{footsepline}{\color{blue}}
\setheadsepline{2}
\setfootsepline{2}
\begin{document}
\lipsum[1-20]
\end{document}
答案1
一种可能性是
\KOMAoptions{
onpsoddpage={\colorlet{headsepline}{green}},
onpsevenpage={\colorlet{headsepline}{red}}
}
\addtokomafont{headsepline}{\color{headsepline}}
例子:
\documentclass[
%11pt,% default
%a4paper,% default
titlepage,
toc=listof,
toc=bibliography,
headings=standardclasses,
%headings=big,% default
chapterprefix=true,
numbers=noenddot,
twoside=semi,
]{scrreport}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[
automark,
headsepline=2pt,% <- changed
footsepline=2pt% <- changed
]{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles
\ohead{\pagemark}% <- changed
\ihead{\headmark}% <- changed
\addtokomafont{pagehead}{\normalfont\large\scshape}% <- added
\setkomafont{pagenumber}{}% <- added
\KOMAoptions{
onpsoddpage={\colorlet{headsepline}{green}},% green on odd pages
onpsevenpage={\colorlet{headsepline}{red}}% red on even pages
}
\addtokomafont{headsepline}{\color{headsepline}}% <- changed
\addtokomafont{footsepline}{\color{blue}}
\begin{document}
\chapter{Foo}
\section{Bar}
\lipsum[1-20]
\end{document}
补充说明:\setheadsepline
和\setfootsepline
已弃用。请使用选项headsepline=2pt
和footsepline=2pt
代替。