2

I've been trying to add some color swatches to the header. So far I've tried Tikz with the usual header commands of scrlayer-scrpage, but it didn't work out well. I almost did it, but two problems remain:

  1. There is effectively no "background", the layer hides the header content;
  2. The headers aren't symmetrical (odd and even pages)

enter image description here

The page number, as can be seen in the code (relevant part adapted from here), needs to be inside the darker rectangle, outside of the text block.

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

Any other possible or simpler solutions, e.g. with TiKz, would be most welcome, too.

3

You have to use \AddLayersAtBeginOfPageStyle to add the layers before the default layers of scrheadings.

But I am note sure what the desired result is. Maybe something like

enter image description here

Code:

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

Note: If the layers should be added to every page style (and not only scrheadings) as mentioned in a comment of your code then you can use

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

or

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

Update

If the pagenumber should be on the baseline of the header, I would use

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

enter image description here

2
  • That's great. If fact, it's better and cleaner than I expected. If I wanted to change \pagemark to be on the baseline of the header, what should I do? I tried changing \putC and \makebox, but to no avail. – user9424 Mar 26 '18 at 14:45
  • To ensure that the page number is on the baseline of the header I would add \pagemark to \rohead and \lehead. See my updated answer. – esdd Mar 26 '18 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy