使用 scrlayer-scrpage 实现对称标题层

使用 scrlayer-scrpage 实现对称标题层

我一直在尝试向标题添加一些颜色样本。到目前为止,我已经尝试使用 Tikz 的常用标题命令scrlayer-scrpage,但效果不佳。我几乎做到了,但仍有两个问题:

  1. 实际上没有“背景”,该层隐藏了标题内容;
  2. 页眉不对称(奇数页和偶数页)

在此处输入图片描述

页码,如代码所示(相关部分改编自这里),需要位于较暗的矩形内,文本块的外部。

\documentclass[twoside]{scrartcl}
\usepackage[papersize={216mm,280mm},
inner=22mm,
outer=26mm,
footskip=11mm,
top=24mm, 
bottom=23mm,
headsep=7mm,
footnotesep=4mm,
columnsep=6mm,
]{geometry}

\usepackage{xcolor}

\usepackage{lipsum,blindtext}

\usepackage[%headsepline=true,
footsepline=true,plainfootsepline]
{scrlayer-scrpage}

\pagestyle{scrheadings}
\clearpairofpagestyles %use after defining page style
\rohead{Lorem ipsum dolor sit amet}
\lehead{\llap{\pagemark\hspace{4mm}}AUTOR}


\lefoot*{Some very very long name}
\rofoot*{Some very very long name}
\setkomafont{pageheadfoot}{\sff\footnotesize}
\setkomafont{pagenumber}{\sffamily}


\DeclareNewLayer[
background,
oddpage,
align=tr,
hoffset=\paperwidth,
voffset=0pt,%distance from top
%width=1cm,% width of the swatch
width=\paperwidth,
height=\dimexpr\voffset+1in+\topmargin+\headheight\relax,% height of the swatch
contents={\textcolor{lightgray!50}{\rule{9mm}{\layerheight}}
    \textcolor{lightgray!70!black}{\rule{15mm}{\layerheight}} \textcolor{lightgray!50}{\rule{190mm}{\layerheight}}
}% end contents
]{swatch.odd}

\DeclareNewLayer[
clone=swatch.odd,
evenpage,
align=l,
%align=tl,
hoffset=0pt
]{swatch.even}

% add layers to every pagestyle
\AddLayersToPageStyle{scrheadings}{swatch.odd,swatch.even}



\begin{document}
\lipsum[1-10]
\end{document}

任何其他可能或更简单的解决方案,例如使用 TiKz,也将受到欢迎。

答案1

您必须使用\AddLayersAtBeginOfPageStyle在默认图层之前添加图层scrheadings

但我不确定期望的结果是什么。也许是这样的

在此处输入图片描述

代码:

\documentclass[twoside]{scrartcl}
\usepackage[papersize={216mm,280mm},
inner=22mm,
outer=26mm,
footskip=11mm,
top=24mm, 
bottom=23mm,
headsep=7mm,
footnotesep=4mm,
columnsep=6mm,
]{geometry}

\usepackage{xcolor}

\usepackage{lipsum}

\usepackage[footsepline=true,plainfootsepline]
  {scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles
\rohead{Lorem ipsum dolor sit amet}
\lehead{AUTOR}

\ofoot*{Some very very long name}
\setkomafont{pageheadfoot}{\sffamily\footnotesize}
\setkomafont{pagenumber}{\sffamily\bfseries}

\DeclareNewLayer[
  background,
  topmargin,
  addheight=\headheight,
  mode=picture,
  contents=\putLL{\textcolor{lightgray!50}{\rule{\layerwidth}{\layerheight}}}
]{swatch.bg}
\DeclareNewLayer[
  clone=swatch.bg,
  oddpage,
  outermargin,
  addhoffset=2mm,
  width=18mm,
  height=\dimexpr1in+\voffset+\topmargin+\headheight\relax,
  contents={
    \putLL{%
    \textcolor{white}{\rule{1.5mm}{\layerheight}}%
    \textcolor{lightgray!70!black}{\rule{15mm}{\layerheight}}%
    \textcolor{white}{\rule{1.5mm}{\layerheight}}%
    }
    \putC{\makebox(0,0){\pagemark}}
}
]{swatch.odd}
\DeclareNewLayer[
  clone=swatch.odd,
  evenpage,
  addhoffset=\dimexpr1in+\hoffset+\evensidemargin-4mm-18mm\relax
]{swatch.even}
% add the layers to pagestyle scrheadings:
\AddLayersAtBeginOfPageStyle{scrheadings}{swatch.odd,swatch.even,swatch.bg}

\begin{document}
\lipsum[1-20]
\end{document}

注意:如果应该将图层添加到每个页面样式(而不仅仅是scrheadings),如代码注释中所述,那么您可以使用

\AddLayersAtBeginOfPageStyle{@everystyle@}{swatch.odd,swatch.even,swatch.bg}

或者

\AddLayersToPageStyle{@everystyle@}{swatch.bg,swatch.odd,swatch.even}% order changed!

更新

如果页码应该位于页眉的基线上,我会使用

\documentclass[twoside]{scrartcl}
\usepackage[papersize={216mm,280mm},
inner=22mm,
outer=26mm,
footskip=11mm,
top=24mm, 
bottom=23mm,
headsep=7mm,
footnotesep=4mm,
columnsep=6mm,
]{geometry}

\usepackage{xcolor}

\usepackage{lipsum}

\usepackage[footsepline=true,plainfootsepline]
  {scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles
\rohead{Lorem ipsum dolor sit amet\makebox[0pt][l]{\hspace*{2mm}\makebox[18mm]{\centering\pagemark}}}
\lehead{\makebox[0pt][r]{\makebox[18mm]{\centering\pagemark}\hspace*{2mm}}AUTOR}

\ofoot*{Some very very long name}
\setkomafont{pageheadfoot}{\sffamily\footnotesize}
\setkomafont{pagenumber}{\sffamily\bfseries}

\DeclareNewLayer[
  background,
  topmargin,
  addheight=\headheight,
  mode=picture,
  contents=\putLL{\textcolor{lightgray!50}{\rule{\layerwidth}{\layerheight}}}
]{swatch.bg}
\DeclareNewLayer[
  clone=swatch.bg,
  oddpage,
  outermargin,
  addhoffset=2mm,
  width=18mm,
  height=\dimexpr1in+\voffset+\topmargin+\headheight\relax,
  contents={\usekomafont{pageheadfoot}\usekomafont{pagehead}
    \putLL{%
    \textcolor{white}{\rule{1.5mm}{\layerheight}}%
    \textcolor{lightgray!70!black}{\rule{15mm}{\layerheight}}%
    \textcolor{white}{\rule{1.5mm}{\layerheight}}%
    }
}
]{swatch.odd}
\DeclareNewLayer[
  clone=swatch.odd,
  evenpage,
  addhoffset=\dimexpr1in+\hoffset+\evensidemargin-4mm-18mm\relax
]{swatch.even}
% add the layers to pagestyle scrheadings:
\AddLayersAtBeginOfPageStyle{scrheadings}{swatch.odd,swatch.even,swatch.bg}

\begin{document}
\lipsum[1-20]
\end{document}

在此处输入图片描述

相关内容