| 1 |
% ====================================================================== |
| 2 |
% scrlayer-scrpage-experts-en.tex |
| 3 |
% Copyright (c) Markus Kohm, 2013-2025 |
| 4 |
% |
| 5 |
% This file is part of the LaTeX2e KOMA-Script bundle. |
| 6 |
% |
| 7 |
% This work may be distributed and/or modified under the conditions of |
| 8 |
% the LaTeX Project Public License, version 1.3c of the license. |
| 9 |
% The latest version of this license is in |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 12 |
% version 2005/12/01 or later and of this work. |
| 13 |
% |
| 14 |
% This work has the LPPL maintenance status "author-maintained". |
| 15 |
% |
| 16 |
% The Current Maintainer and author of this work is Markus Kohm. |
| 17 |
% |
| 18 |
% This work consists of all files listed in MANIFEST.md. |
| 19 |
% ====================================================================== |
| 20 |
% |
| 21 |
% Expert chapter about scrlayer-scrpage of the KOMA-Script guide |
| 22 |
% |
| 23 |
% ============================================================================ |
| 24 |
|
| 25 |
\KOMAProvidesFile{scrlayer-scrpage-experts-en.tex}% |
| 26 |
[$Date: 2025-07-16 10:53:10 +0200 (Mi, 16. Jul 2025) $ |
| 27 |
KOMA-Script guide (chapter: scrlayer-scrpage-experts)] |
| 28 |
\translator{Markus Kohm\and Karl Hagen} |
| 29 |
|
| 30 |
\chapter[{Additional Features of \Package{scrlayer-scrpage}}] |
| 31 |
{Additional Features\ChangedAt{v3.12}{\Package{scrlayer-scrpage}} with |
| 32 |
the \Package{scrlayer-scrpage} package} |
| 33 |
\labelbase{scrlayer-scrpage-experts} |
| 34 |
% |
| 35 |
\BeginIndexGroup |
| 36 |
\BeginIndex{Package}{scrlayer-scrpage}% |
| 37 |
The \Package{scrlayer-scrpage} package offers many features beyond what has |
| 38 |
been described in \autoref{cha:scrlayer-scrpage} of \autoref{part:forAuthors} |
| 39 |
of this \iffree{guide}{book}. However, the average user will not normally need |
| 40 |
these extensions, and some of them are only provided for compatibility with |
| 41 |
\Package{scrpage2}. The documentation here in \autoref{part:forExperts} serves |
| 42 |
to deepen and broaded your knowledge, and its mastery goes beyond basic |
| 43 |
skills. |
| 44 |
|
| 45 |
\LoadCommonFile{pagestylemanipulation}% \section{Manipulating Defined Page Styles} |
| 46 |
|
| 47 |
\section{Defining New Pairs of Page Styles} |
| 48 |
\seclabel{pagestyle.pairs} |
| 49 |
|
| 50 |
The two page styles \PageStyle{scrheadings} and \PageStyle{plain.scrheadings} |
| 51 |
were described in \autoref{sec:scrlayer-scrpage.predefined.pagestyles}. You |
| 52 |
can view them as a kind of pair, with \PageStyle{scrheadings} intended as the |
| 53 |
main page style for a running head and \PageStyle{plain.scrheadings} the |
| 54 |
corresponding \PageStyle{plain} page style without a running head but |
| 55 |
generally with pagination. In addition to configuring this predefined pair, |
| 56 |
\Package{scrlayer-scrpage} also lets you define additional pairs of page |
| 57 |
styles. The name of the main page style, for example \PageStyle{scrheadings}, |
| 58 |
also serves as the name of the page-style pair. |
| 59 |
|
| 60 |
\iffree{ |
| 61 |
The vast majority of users will not need more than the one predefined |
| 62 |
page-style pair, \PageStyle{scrheadings}. So the commands documented in this |
| 63 |
section are therefore extensions for special cases. Since I have not come |
| 64 |
across any suitable applications while writing this manual, there are no |
| 65 |
detailed examples. Should I ever run across a particularly nice application |
| 66 |
while providing support, I will happily include it in future versions. At |
| 67 |
the same time, however, I'm virtually certain that all such cases could also |
| 68 |
be solved using the predefined pair only.}{} |
| 69 |
|
| 70 |
\begin{Declaration} |
| 71 |
\Macro{defpairofpagestyles}% |
| 72 |
\OParameter{parent pair}\Parameter{name}\Parameter{definition}% |
| 73 |
\Macro{newpairofpagestyles}% |
| 74 |
\OParameter{parent pair}\Parameter{name}\Parameter{definition}% |
| 75 |
\Macro{renewpairofpagestyles}% |
| 76 |
\OParameter{parent pair}\Parameter{name}\Parameter{definition}% |
| 77 |
\Macro{providepairofpagestyles}% |
| 78 |
\OParameter{parent pair}\Parameter{name}\Parameter{definition} |
| 79 |
\end{Declaration} |
| 80 |
You can use these commands to define pairs of page styles similar to |
| 81 |
\PageStyle{scrheadings} and \PageStyle{plain.scrheadings}, where \PName{name} |
| 82 |
is the name of the main page style corresponding to \PageStyle{scrheadings}. |
| 83 |
The name of the equivalent \PageStyle{plain} page style will be prefixed by |
| 84 |
\PValue{plain.} automatically. So \PName{name} is not only the name of the |
| 85 |
pair of page styles, but also the name of the main page style of that pair, |
| 86 |
while \PValue{plain.}\PName{name} is the name of the \PageStyle{plain} page |
| 87 |
style of this pair. |
| 88 |
|
| 89 |
If you provide the optional \PName{parent pair} argument, this is the name of |
| 90 |
a page-style pair whose settings are used to initialise the new page-style |
| 91 |
pair. So the new pair inherits the configuration of the \PName{parent pair}. |
| 92 |
|
| 93 |
Although \autoref{sec:scrlayer-scrpage.predefined.pagestyles} might have |
| 94 |
created the impression that the commands described there apply only to |
| 95 |
\PageStyle{scrheadings} and \PageStyle{plain.scrheadings} only, this is true |
| 96 |
only so long as those two page styles are the only defined page-style pair. As |
| 97 |
soon as there are multiple page-style pairs, |
| 98 |
\DescRef{scrlayer-scrpage.cmd.lehead}, \DescRef{scrlayer-scrpage.cmd.cehead}, |
| 99 |
\DescRef{scrlayer-scrpage.cmd.rehead}, \DescRef{scrlayer-scrpage.cmd.lohead}, |
| 100 |
\DescRef{scrlayer-scrpage.cmd.cohead}, \DescRef{scrlayer-scrpage.cmd.rohead}, |
| 101 |
\DescRef{scrlayer-scrpage.cmd.lefoot}, \DescRef{scrlayer-scrpage.cmd.cefoot}, |
| 102 |
\DescRef{scrlayer-scrpage.cmd.refoot}, \DescRef{scrlayer-scrpage.cmd.lofoot}, |
| 103 |
\DescRef{scrlayer-scrpage.cmd.cofoot}, \DescRef{scrlayer-scrpage.cmd.rofoot}, |
| 104 |
\DescRef{scrlayer-scrpage.cmd.ihead}, \DescRef{scrlayer-scrpage.cmd.chead}, |
| 105 |
\DescRef{scrlayer-scrpage.cmd.ohead}, \DescRef{scrlayer-scrpage.cmd.ifoot}, |
| 106 |
\DescRef{scrlayer-scrpage.cmd.cfoot}, and \DescRef{scrlayer-scrpage.cmd.ofoot} |
| 107 |
all refer to page-style pair that was most recently activated. |
| 108 |
|
| 109 |
In addition to those eighteen commands mentioned above, the three commands |
| 110 |
described below, \DescRef{\LabelBase.cmd.clearmainofpairofpagestyles}, |
| 111 |
\DescRef{\LabelBase.cmd.clearplainofpairofpagestyles}, and |
| 112 |
\DescRef{\LabelBase.cmd.clearpairofpagestyles}, are designed to be used inside |
| 113 |
the \PName{definition} argument. In this case, they represent a kind of |
| 114 |
default configuration of the page-style pair that is executed each time the |
| 115 |
pair is activated. You activate a page-style pair by activating either one two |
| 116 |
page styles in the pair. Typically, you do so with |
| 117 |
\DescRef{maincls.cmd.pagestyle}\IndexCmd{pagestyle}. |
| 118 |
|
| 119 |
Note that the commands of \autoref{sec:scrlayer-scrpage.pagestyle.content} on |
| 120 |
\autopageref{sec:scrlayer-scrpage.pagestyle.content} are general in nature and |
| 121 |
apply to all page styles defined with \Package{scrlayer-scrpage}. |
| 122 |
|
| 123 |
Although \Macro{defpairofpagestyles} defines a page-style pair regardless of |
| 124 |
whether the corresponding page styles already exist, |
| 125 |
\Macro{newpairofpagestyles} and \Macro{providepairofpagestyles} do so only if |
| 126 |
the page styles are currently undefined. If at least one of the page styles is |
| 127 |
already defined, the new definition of \Macro{providepairofpagestyles} will be |
| 128 |
ignored, whereas using \Macro{newpairofpagestyles} results in an error |
| 129 |
message. To redefine existing page-style pairs, you can use |
| 130 |
\Macro{renewpairofpagestyles}. With this an is thrown if either one of the two |
| 131 |
page styles of the pair does not already exist.% |
| 132 |
\EndIndexGroup |
| 133 |
|
| 134 |
|
| 135 |
\begin{Declaration} |
| 136 |
\Macro{clearmainofpairofpagestyles}% |
| 137 |
\Macro{clearplainofpairofpagestyles}% |
| 138 |
\Macro{clearpairofpagestyles} |
| 139 |
\end{Declaration} |
| 140 |
The \Macro{clearmainofpairofpagestyles} command sets the main page style of |
| 141 |
the most recently activated page-style pair to be empty. In contrast, the |
| 142 |
\Macro{clearplainofpairofpagestyles} command sets the \PageStyle{plain} page |
| 143 |
style of the active page-style pair to be empty. Finally, |
| 144 |
\Macro{clearpairofpagestyle} sets both page styles of the activate pair to be |
| 145 |
empty. |
| 146 |
|
| 147 |
But note\textnote{Attention!} that none of these commands removes the |
| 148 |
definitions of the \PName{definition} argument that was specified when |
| 149 |
defining the page-style pair (see above). So if you activate the pair of page |
| 150 |
styles again, those definitions will be used again! |
| 151 |
|
| 152 |
You can use these commands inside the \PName{definition} of the page-style |
| 153 |
pair explained above. But you can also use them outside this definition. In |
| 154 |
this case, they refer to the most recently activated page-style pair.% |
| 155 |
\EndIndexGroup |
| 156 |
|
| 157 |
|
| 158 |
\section{Defining Complex Page Styles} |
| 159 |
\seclabel{pagestyle.experts} |
| 160 |
|
| 161 |
In addition to the predefined page styles, \Package{scrlayer-scrpage} also |
| 162 |
provides a more basic interface for defining new page styles. The page-style |
| 163 |
definitions discussed so far use this interface internally, as do the obsolete |
| 164 |
commands in \autoref{sec:\LabelBase.pagestyle.triple}. |
| 165 |
\Package{scrlayer-scrpage}. Because of its complexity, however, only advanced |
| 166 |
users should try to use it directly. Less experienced users can already |
| 167 |
achieve almost everything possible with this low-level interface by using the |
| 168 |
possibilities described previously. |
| 169 |
|
| 170 |
We expressly advise against using the commands presented here to redefine |
| 171 |
individual parts of already defined page style pairs. Among other things, this |
| 172 |
would damage the link to a pair. For the redefinition of page style pairs, |
| 173 |
please refer to \autoref{sec:\LabelBase.pagestyle.pairs} from |
| 174 |
\autopageref{sec:\LabelBase.pagestyle.pairs}. |
| 175 |
|
| 176 |
\begin{Declaration} |
| 177 |
\Macro{defpagestyle}% |
| 178 |
\Parameter{name}\Parameter{header specification}\Parameter{footer specification}% |
| 179 |
\Macro{newpagestyle}% |
| 180 |
\Parameter{name}\Parameter{header specification}\Parameter{footer specification}% |
| 181 |
\Macro{providepagestyle}% |
| 182 |
\Parameter{name}\Parameter{header specification}\Parameter{footer specification}% |
| 183 |
\Macro{renewpagestyle}% |
| 184 |
\Parameter{name}\Parameter{header specification}\Parameter{footer specification}% |
| 185 |
\end{Declaration} |
| 186 |
You can use these commands to define a single page style with maximum |
| 187 |
flexibility, where \PName{name} is the name of the page style that you want to |
| 188 |
define. |
| 189 |
|
| 190 |
The parameters \PName{header specification} and \PName{footer specification} |
| 191 |
have identical structure: |
| 192 |
\begin{quote}\raggedright |
| 193 |
\texttt{% |
| 194 |
(\PName{length of the line above},\PName{thickness of the line above})\%\\ |
| 195 |
\Parameter{specification for the left page in two-side layout}\%\\ |
| 196 |
\Parameter{specification for the right page in two-side layout}\%\\ |
| 197 |
\Parameter{specification for all pages in one-side laypout}\%\\ |
| 198 |
(\PName{length of the line below},\PName{thickness of the line below})% |
| 199 |
} |
| 200 |
\end{quote} |
| 201 |
The arguments in the round brackets are optional. That is, you can omit them |
| 202 |
together with the brackets. In that case, the length and thickness of the |
| 203 |
corresponding horizontal rules are based on the \KOMAScript{} options |
| 204 |
\DescRef{scrlayer-scrpage.option.headtopline}, |
| 205 |
\DescRef{scrlayer-scrpage.option.headsepline}, |
| 206 |
\DescRef{scrlayer-scrpage.option.footsepline}, and |
| 207 |
\DescRef{scrlayer-scrpage.option.footbotline} (see |
| 208 |
\autoref{sec:scrlayer-scrpage.pagestyle.content}, |
| 209 |
\DescPageRef{scrlayer-scrpage.option.headtopline}). |
| 210 |
|
| 211 |
All three arguments in curly brackets are mandatory and are used depending on |
| 212 |
the page and the layout settings. Their content can be anything you want. For |
| 213 |
page styles with running heads, however, you should use |
| 214 |
\DescRef{scrlayer-scrpage.cmd.headmark}, |
| 215 |
\DescRef{scrlayer-scrpage.cmd.leftmark}, or |
| 216 |
\DescRef{scrlayer-scrpage.cmd.rightmark} inside the specification. Under no |
| 217 |
circumstances should you directly put the number or text of a sectioning |
| 218 |
command here. Because of the \LaTeX{}'s asynchronous page construction, the |
| 219 |
wrong numbers or text can appear in the header or footer if you do so. |
| 220 |
|
| 221 |
The \Macro{defpagestyle} command defines the page style regardless of whether |
| 222 |
it already exists or not. In contrast, \Macro{newpagestyle} throws an error if |
| 223 |
a page style of the same \PName{name} already exists. On the other hand, |
| 224 |
\Macro{providepagestyle} simply ignores the definition if the \PName{name} has |
| 225 |
already been used for a page style. Conversely, \Macro{renewpagestyle} can |
| 226 |
only redefine an existing page style. For a new \PName{name}, it throws an |
| 227 |
error. |
| 228 |
|
| 229 |
All four commands are based on the |
| 230 |
\DescRef{scrlayer.cmd.DeclarePageStyleByLayers}% |
| 231 |
\IndexCmd{DeclarePageStyleByLayers} command of the |
| 232 |
\hyperref[cha:scrlayer]{\Package{scrlayer}}\IndexPackage{scrlayer} package. |
| 233 |
You can find the layers that are defined for a page style \PName{name} in |
| 234 |
\autoref{tab:scrlayer-scrpage-experts.layersperstyle}, and more information |
| 235 |
about layers and layer-page in \autoref{cha:scrlayer}, starting on |
| 236 |
\autopageref{cha:scrlayer}.% |
| 237 |
|
| 238 |
\begin{table} |
| 239 |
% \KOMAoptions{captions=topbeside} |
| 240 |
% \setcapindent{0pt} |
| 241 |
% \begin{captionbeside} |
| 242 |
\caption |
| 243 |
[{The layers \Package{scrlayer-scrpage} defines for a page style}] |
| 244 |
{The layers \Package{scrlayer-scrpage} defines for a \PName{name} page |
| 245 |
style\label{tab:scrlayer-scrpage-experts.layersperstyle}} |
| 246 |
% [l] |
| 247 |
\begin{tabular}{ll} |
| 248 |
\toprule |
| 249 |
Name of the layer & Meaning of the layer \\ |
| 250 |
\midrule |
| 251 |
\PName{name}\PValue{.head.above.line} |
| 252 |
& horizontal line above the header\\ |
| 253 |
\PName{name}\PValue{.head.odd} |
| 254 |
& header of odd pages in two-sided printing\\ |
| 255 |
\PName{name}\PValue{.head.even} |
| 256 |
& header of even pages in two-sided printing\\ |
| 257 |
\PName{name}\PValue{.head.oneside} |
| 258 |
& header in one-sided printing\\ |
| 259 |
\PName{name}\PValue{.head.below.line} |
| 260 |
& horizontal line below the header\\ |
| 261 |
\PName{name}\PValue{.foot.above.line} |
| 262 |
& horizontal line above the footer\\ |
| 263 |
\PName{name}\PValue{.foot.odd} |
| 264 |
& footer of odd pages in two-sided printing\\ |
| 265 |
\PName{name}\PValue{.foot.even} |
| 266 |
& footer of even pages in two-sided printing\\ |
| 267 |
\PName{name}\PValue{.foot.oneside} |
| 268 |
& footer in one-sided printing\\ |
| 269 |
\PName{name}\PValue{.foot.below.line} |
| 270 |
& horizontal line below the footer\\ |
| 271 |
\bottomrule |
| 272 |
\end{tabular} |
| 273 |
% \end{captionbeside} |
| 274 |
\end{table} |
| 275 |
|
| 276 |
\begin{Example} |
| 277 |
Suppose you want to set a background colour for the header of the |
| 278 |
\PageStyle{scrheadings} page style. From the introduction to this chapter |
| 279 |
and \autoref{tab:scrlayer-scrpage-experts.layersperstyle}, you know that |
| 280 |
\PageStyle{scrheadings} is a layer page style that includes the layers |
| 281 |
\PValue{scrheadings.head.even}, \PValue{scrheadings.head.odd}, and |
| 282 |
\PValue{scrheadings.head.oneside}. You now define three more layers for |
| 283 |
their backgrounds and add them at the beginning of the page style: |
| 284 |
\begin{lstcode} |
| 285 |
\documentclass{scrartcl} |
| 286 |
\usepackage[automark]{scrlayer-scrpage} |
| 287 |
\usepackage{xcolor} |
| 288 |
\usepackage{blindtext} |
| 289 |
\DeclareLayer[clone=scrheadings.head.oneside, |
| 290 |
contents={% |
| 291 |
\color{yellow}\rule[-\dp\strutbox]{\layerwidth}{\layerheight}% |
| 292 |
}% |
| 293 |
]{scrheadings.head.oneside.background} |
| 294 |
\DeclareLayer[clone=scrheadings.head.odd, |
| 295 |
contents={% |
| 296 |
\color{yellow}\rule[-\dp\strutbox]{\layerwidth}{\layerheight}% |
| 297 |
}% |
| 298 |
]{scrheadings.head.odd.background} |
| 299 |
\DeclareLayer[clone=scrheadings.head.even, |
| 300 |
contents={% |
| 301 |
\color{yellow}\rule[-\dp\strutbox]{\layerwidth}{\layerheight}% |
| 302 |
}% |
| 303 |
]{scrheadings.head.even.background} |
| 304 |
\AddLayersAtBeginOfPageStyle{scrheadings}{% |
| 305 |
scrheadings.head.oneside.background,% |
| 306 |
scrheadings.head.odd.background,% |
| 307 |
scrheadings.head.even.background% |
| 308 |
} |
| 309 |
\pagestyle{scrheadings} |
| 310 |
\begin{document} |
| 311 |
\blinddocument |
| 312 |
\end{document} |
| 313 |
\end{lstcode} |
| 314 |
As you can see, the example uses three layers so that the position and size |
| 315 |
of the background layers could simply be copied from the corresponding |
| 316 |
header layer using the \Option{clone} option. This is easier than using only |
| 317 |
one background layer and dynamically calculating its position each time. |
| 318 |
|
| 319 |
The coloured background itself was created using a \Macro{rule} command. The |
| 320 |
size arguments of this \Macro{rule} are given by |
| 321 |
\DescRef{scrlayer.cmd.layerwidth} and \DescRef{scrlayer.cmd.layerheight} |
| 322 |
which contain the current width and height of the layer itself. The optional |
| 323 |
argument of \Macro{rule} is used to move the rule down by the height of a |
| 324 |
descender. |
| 325 |
\end{Example} |
| 326 |
% |
| 327 |
Instead of using new layers to colour the background in the example above, |
| 328 |
\Macro{colorbox} and \DescRef{scrlayer-scrpage.cmd.chead} could have been |
| 329 |
used. You can work out a solution using this method as an exercise. Likewise, |
| 330 |
you could have added the background layers individually just before the |
| 331 |
corresponding content layer. You can implement this as an exercise too.% |
| 332 |
\EndIndexGroup |
| 333 |
|
| 334 |
\section{Defining Simple Page Styles with a Tripartite Header and Footer} |
| 335 |
\seclabel{pagestyle.triple} |
| 336 |
|
| 337 |
\LoadNonFree{scrlayer-scrpage-experts}{1} |
| 338 |
|
| 339 |
\section{Legacy Features of \Package{scrpage2}} |
| 340 |
\seclabel{obsolete} |
| 341 |
|
| 342 |
\begin{Explain} |
| 343 |
The \Package{scrlayer-scrpage} package contains some legacy features that |
| 344 |
derive from \Package{scrpage2} and exist only to be as compatible as possible |
| 345 |
with that package. Users only need to understand these features if they want |
| 346 |
to edit an old document based on \Package{scrpage2}. You\textnote{Attention!} |
| 347 |
should not use the items documented here in new documents! |
| 348 |
\end{Explain} |
| 349 |
|
| 350 |
\begin{Declaration} |
| 351 |
\OptionVName{hmode}{simple switch} |
| 352 |
\end{Declaration} |
| 353 |
The \Package{scrpage2} package always outputs headers and footers in |
| 354 |
horizontal mode. In contrast, \Package{scrlayer-scrpage} in the default |
| 355 |
setting only switches into horizontal mode when horizontal material is output. |
| 356 |
However, if you activate the \Option{hmode} option, \Package{scrlayer-scrpage} |
| 357 |
will behave like \Package{scrpage2} and switch to horizontal mode before any |
| 358 |
output. This can affect both the processing of white space at the beginning of |
| 359 |
the output and vertical alignment. |
| 360 |
|
| 361 |
The options recognizes the standard values for simple switches listed in |
| 362 |
\autoref{tab:truefalseswitch} on \autopageref{tab:truefalseswitch}. The option |
| 363 |
is deactivated by default.% |
| 364 |
\EndIndexGroup |
| 365 |
|
| 366 |
\LoadNonFree{scrlayer-scrpage-experts}{0} |
| 367 |
% |
| 368 |
\EndIndexGroup |
| 369 |
|
| 370 |
%%% Local Variables: |
| 371 |
%%% mode: latex |
| 372 |
%%% TeX-master: "scrguide-en.tex" |
| 373 |
%%% coding: utf-8 |
| 374 |
%%% ispell-local-dictionary: "en_GB" |
| 375 |
%%% eval: (flyspell-mode 1) |
| 376 |
%%% End: |