将 scrlayer-scrpage 标题文本置于标题的中心

将 scrlayer-scrpage 标题文本置于标题的中心

我利用 google + 复制/粘贴功能获得了一个我喜欢的外观的标题,即纯色带 + 文本。但不幸的是,文本不在带内居中,我不知道如何让它移动(至少从预先浏览 KOMA-script 的文档来看)。此外,虽然我可以想象有某种方法可以稍微移动它,但我还是很想中心将其放在标题内,而不仅仅是强制其向上移动X毫米。

标头

平均能量损失

\documentclass[12pt,a4paper,oneside]{scrreprt}

\usepackage[automark]{scrlayer-scrpage}

\clearpairofpagestyles
\cfoot[\pagemark]{\pagemark}
\chead{\leftmark} % section on the inner (oneside: right) side
% \ohead{\rightmark} % subsection on the outer (oneside: left) side
\addtokomafont{pagehead}{\bfseries\upshape\color{contrastColour}} % header upshape instead italic
\addtokomafont{pagenumber}{\bfseries\color{primaryColour}}
% \renewcommand{\headfont}{\color{schrift}\normalfont\slshape}

% Defining the Layer
% \makeatletter
\newlength{\topheight}
\setlength{\topheight}{\sls@topmargin}
\addtolength{\topheight}{\headheight}
\DeclareLayer[
    background,
    contents={%
        \color{primaryColour}%
        \rule{\paperwidth}{\topheight}%

    }%
]{scrheadings.head.background}
% \makeatother

%Adding the Layer to the pagestyles
\AddLayersAtBeginOfPageStyle{scrheadings}{%
    scrheadings.head.background,%
}
\AddLayersAtBeginOfPageStyle{plain.scrheadings}{%
scrheadings.head.background}

\begin{document}

\chapter{Demo Chapter}

\end{document}

答案1

scrheadings.head.您必须从和开始移动图层plain.scrheadings.head.

\documentclass[12pt]{scrreprt}
\usepackage{blindtext}% only for dummy text

\usepackage{xcolor}
\usepackage[automark]{scrlayer-scrpage}

\clearpairofpagestyles
\cfoot*{\pagemark}
\chead{\headmark}

\addtokomafont{pagehead}{\bfseries\upshape\color{white}}
\addtokomafont{pagenumber}{\bfseries\color{blue}}

% shift the predefined head layers
\ForEachLayerOfPageStyle*{scrheadings}{%
  \ifstrstart{#1}{scrheadings.head.}
    {\ModifyLayer[addvoffset=-.5in-.5\voffset-.5\topmargin]{#1}}
    {}%
}
\ForEachLayerOfPageStyle*{plain.scrheadings}{%
  \ifstrstart{#1}{plain.scrheadings.head.}
    {\ModifyLayer[addvoffset=-.5in-.5\voffset-.5\topmargin]{#1}}
    {}%
}

% Defining the Layer
\DeclareLayer[
    background,
    topmargin,
    addheight=\headheight,
    contents={%
        \color{blue!30!black}%
        \rule{\layerwidth}{\layerheight}%
    }%
]{my.head.background}

%Adding the Layer to the pagestyles
\AddLayersAtBeginOfPageStyle{scrheadings}{my.head.background}
\AddLayersAtBeginOfPageStyle{plain.scrheadings}{my.head.background}

\begin{document}
\Blinddocument
\end{document}

结果:

在此处输入图片描述

补充说明:如果可能的话,避免使用内部 KOMA-Script 命令,例如\sls@topmargin

相关内容