scrlayer-scrpage 将我的标题与几何和边距对齐

scrlayer-scrpage 将我的标题与几何和边距对齐

我正在尝试复制标题koma-script-manual到目前为止一切都很顺利,尽管我需要使用几何学设置我的特定 typearea。如果我使用scrlayer-scrpage设置我的标题,标题会神奇地获得一个偏移量。更奇怪的是 - 偏移量取决于加载顺序geometry- 在偏移量为正之前加载scrlayer-scrpage- 在偏移量为负之后加载。有什么想法为什么会发生这种情况以及如何修复它? 使用 geometry 和 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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

答案1

scrlayer-scrpage通过 布局设置后加载包geometry。但您必须设置标题的偏移量。请参阅文档以获取有关如果键的偏移量部分缺失会发生什么的信息headwidth

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

或者

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

在此处输入图片描述

代码:

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

补充说明:

背景层的一个定义就足够了。

有关 KOMA-Script 文档中标题的原始定义,请参阅scrguide.cls

相关内容