2

I'm trying to copy the header from koma-script-manual. So far everything worked out fine, although I needed to use geometry to set my specific typearea. If I use scrlayer-scrpage to set my header the header magically gets an offset. Even more odd - the offset depends on the loading order of geometry - loaded before scrlayer-scrpage the offset is positive - loaded after it's negative. Any ideas why this happens and how to fix it? header offset with geometry and scrlayer-scrpage

%%%%%%%%%%%%%%% DOCUMENTCLASS
\documentclass[%
    paper=a4,%
    parskip=never,% 
    fontsize=10pt% 
    ]{scrartcl}%
%%%%%%%%%%%%%%% TYPEAREA
\usepackage{geometry}%
\geometry{
left=2mm,% 
right=2mm,%
top=0mm,%
bottom=2mm,%
includehead,%
includemp,%
headsep=2mm,%
nofoot,%
marginparwidth=20mm,% 
marginparsep=2mm,%
reversemp%
}%
%%%%%%%%%%%%%%% COLORS
\usepackage{xcolor}%
\definecolor{header-background}{RGB}{135,206,250}
%%%%%%%%%%%%%%% HEADER/FOOTER
\usepackage[%
    automark,%
    headwidth=paper,%
    headsepline% +
    ]{scrlayer-scrpage}%
\pagestyle{scrheadings}%
\clearpairofpagestyles% 
\ihead*{Some Title}%
\ohead*{\pagemark}% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% from scrguide to color header
\DeclareLayer[clone=scrheadings.head.oneside,
contents={%
\color{header-background}%
\rule[-\dp\strutbox]%
{\layerwidth}{\layerheight}%
}%
]{scrheadings.head.oneside.background}
\DeclareLayer[clone=scrheadings.head.odd,
contents={%
\color{header-background}%
\rule[-\dp\strutbox]%
{\layerwidth}{\layerheight}%
}%
]{scrheadings.head.odd.background}
\DeclareLayer[clone=scrheadings.head.even,
contents={%
\color{header-background}%
\rule[-\dp\strutbox]%
{\layerwidth}{\layerheight}%
}%
]{scrheadings.head.even.background}
\AddLayersAtBeginOfPageStyle{scrheadings}{%
scrheadings.head.oneside.background,%
scrheadings.head.odd.background,%
scrheadings.head.even.background%
}
%%%%%%%%%%%%%%% DEBUG   
\usepackage{lipsum}% adds lipsum
\usepackage{layout}% shows layout on page
\makeatletter% layout in mm
    \renewcommand*{\lay@value}[2]{%
    \strip@pt\dimexpr0.351459\dimexpr\csname#2\endcsname\relax\relax mm%
    }%
\makeatother%
\KOMAoptions{%
%   draft=true% small black boxes in overfull lines
overfullrule=true% like draft - sometimes works better
}%
%   \geometry{showframe}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\lipsum
\newpage
\layout
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2

Load package scrlayer-scrpage after the layout settings by geometry. But you have to set the offset for the header. See the documentation to get information what happens if the offset part is missing for the headwidth key.

\usepackage[%
  automark,%
  headwidth=paper:-\the\oddsidemargin-1in,% <width>:<offset>
  headsepline%
]{scrlayer-scrpage}

or

\usepackage[%
  automark,%
  headsepline%
]{scrlayer-scrpage}
\KOMAoptions{headwidth=paper:-\oddsidemargin-1in}% <width>:<offset>

enter image description here

Code:

\documentclass[%
  parskip=never,%
  fontsize=10pt% 
]{scrartcl}%

\usepackage{geometry}%
\geometry{
  margin=2mm,% all margins 2mm
  top=0mm,% but top 0mm
  includehead,%
  includemp,%
  headsep=2mm,%
  nofoot,%
  marginparwidth=20mm,% 
  marginparsep=2mm,%
  reversemp%
}%

\usepackage{xcolor}%
\definecolor{header-background}{RGB}{135,206,250}

\usepackage[%
  automark,%
  headsepline%
]{scrlayer-scrpage}% sets page style scrheadings automatically
\KOMAoptions{headwidth=paper:-\oddsidemargin-1in}

\clearpairofpagestyles
\ihead*{Some Title}
\ohead*{\pagemark}

\DeclareLayer[
  clone=scrheadings.head.oneside,
  everyside,% removes restrication to oneside
  oddorevenpage,% removes restrication to oddside
  contents={%
    \color{header-background}%
    \rule[-\dp\strutbox]{\layerwidth}{\layerheight}%
  }
]{scrheadings.head.background}
\AddLayersAtBeginOfPageStyle{scrheadings}{%
  scrheadings.head.background%
}

\usepackage{lipsum}% only for dummy text
\begin{document}%
\lipsum[1-50]
\end{document}

Additional remarks:

One definition of the background layer is enough.

For the original definition of the header in the KOMA-Script documentation have a look in the scrguide.cls.

1
  • \the\oddsidemargin was exactly the "unit" I was searching for @esdd – Jabaal Jul 10 '18 at 10:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.