<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to HowTo_PageHeadBackgroundColor</title><link>https://sourceforge.net/p/koma-script/wiki-en/HowTo_PageHeadBackgroundColor/</link><description>Recent changes to HowTo_PageHeadBackgroundColor</description><atom:link href="https://sourceforge.net/p/koma-script/wiki-en/HowTo_PageHeadBackgroundColor/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 08 Jul 2025 08:43:50 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/koma-script/wiki-en/HowTo_PageHeadBackgroundColor/feed" rel="self" type="application/rss+xml"/><item><title>HowTo_PageHeadBackgroundColor modified by Markus Kohm</title><link>https://sourceforge.net/p/koma-script/wiki-en/HowTo_PageHeadBackgroundColor/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="how-to-set-a-background-color-for-the-page-header"&gt;How to set a background color for the page header&lt;/h1&gt;
&lt;p&gt;The KOMA-Script user guide &lt;a class="" href="https://www.ctan.org/pkg/koma-script/scrguide-ne.pdf" rel="nofollow"&gt;&lt;code&gt;scrguide-en.pdf&lt;/code&gt;&lt;/a&gt; shows a header with a colored background. The question of how to achieve this for any document is therefore almost obvious.&lt;/p&gt;
&lt;p&gt;In KOMA-Script, the &lt;a class="" href="https://www.ctan.org/pkg/scrlayer" rel="nofollow"&gt;&lt;code&gt;scrlayer&lt;/code&gt;&lt;/a&gt; and &lt;a class="" href="https://www.ctan.org/pkg/scrlayer-scrpage" rel="nofollow"&gt;&lt;code&gt;scrlayer-scrpage&lt;/code&gt;&lt;/a&gt; packages are responsible for header and footer definitions that go beyond the possibilities of the KOMA-Script classes. The &lt;code&gt;scrlayer&lt;/code&gt; package provides the basis with the possibility of layer definition and the definition of page styles, which are made up of the application of these layers. The &lt;code&gt;scrlayer-scrpage&lt;/code&gt; package is an usage of these basics, which offers a seamless and convenient integration of the layer page styles with the KOMA-Script classes as well as the standard classes and many other classes based on these two families.&lt;/p&gt;
&lt;p&gt;To color the background of the page header, simply define a new layer:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\DeclareLayer&lt;/span&gt;[
  head,
  background,
  contents=&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\color&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;DeepSkyBlue3&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="k"&gt;\rule&lt;/span&gt;&lt;span class="na"&gt;[-\dp\strutbox]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\layerwidth&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\layerheight&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;
]&lt;span class="nb"&gt;{&lt;/span&gt;head.background&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;head&lt;/code&gt; attribute defines the position and size of the layer so that it exactly covers the page header. You could also define the position and size via the &lt;code&gt;area&lt;/code&gt; feature or individually via &lt;code&gt;voffset&lt;/code&gt;, &lt;code&gt;hoffset&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt; and &lt;code&gt;width&lt;/code&gt;. &lt;code&gt;head&lt;/code&gt; is a welcome simplification here. Further such simplifications for other areas of the pages are documented in the user guides.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;background&lt;/code&gt; attribute indicates that this is a background layer, i.e. a layer that is to be output before the actual page text. &lt;code&gt;scrlayer-scrpage&lt;/code&gt; also outputs the content of the page header itself, i.e. usually the column title with the repetition of chapter or section headings, with this attribute. If you were to use &lt;code&gt;foreground&lt;/code&gt; instead, the colored bar would be output above the actual header content and thus overwrite it. If neither of the two attributes is explicitly specified, the content would be output in the background as well as in the foreground by default, thus also overwriting the actual header content.&lt;/p&gt;
&lt;p&gt;After changing the current color, a &lt;code&gt;\rule&lt;/code&gt; of the size &lt;code&gt;\layerwidth&lt;/code&gt; and &lt;code&gt;\layerheight&lt;/code&gt; is simply output as the content. The two macros &lt;code&gt;\layerwidth&lt;/code&gt; and &lt;code&gt;\layerheight&lt;/code&gt; can be used like lengths within a layer definition and reflect the width and height of the current layer. This is particularly useful for layers that were not defined by explicitly specifying position and size, but by using simplifications such as &lt;code&gt;head&lt;/code&gt;. As a &lt;code&gt;\rule&lt;/code&gt; is normally positioned on the baseline, it is moved down by the depth of a standard text line &lt;code&gt;\dp\strutbox&lt;/code&gt; so that it actually covers the header area exactly.&lt;/p&gt;
&lt;p&gt;As an alternative to moving the layer using the optional argument of &lt;code&gt;\rule&lt;/code&gt;, you could also declare the layer as an image layer instead of a text layer:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\DeclareLayer&lt;/span&gt;[
  background,
  mode=picture,
  head,
  contents=&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\color&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;DeepSkyBlue3&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="k"&gt;\rule&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\layerwidth&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\layerheight&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;
]&lt;span class="nb"&gt;{&lt;/span&gt;head.background&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This means that contents are not output on the baseline, but from the bottom edge of the layer. This is also useful if you want to draw into the layer with a picture environment or &lt;a class="" href="https://www.ctan.org/pkg/pgf" rel="nofollow"&gt;TikZ&lt;/a&gt;, for example to work with a color gradient instead of a single color.&lt;/p&gt;
&lt;p&gt;In addition to declaring the layer, you must of course ensure that the layer is also used. To do this, you add the layer to a page style. &lt;code&gt;scrlayer&lt;/code&gt; offers the option of inserting layers either at the beginning or end of a layer page style or before or after a specific other layer page style. We want the color to be displayed in the background and therefore first, so we add it at the very beginning with &lt;code&gt;\AddLayersAtBeginOfPageStyle&lt;/code&gt;.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\documentclass&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrartcl&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="na"&gt;[x11names]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;xcolor&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="na"&gt;[automark]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrlayer-scrpage&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;blindtext&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\DeclareLayer&lt;/span&gt;[
  background,
  mode=picture,
  head,
  contents=&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\color&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;DeepSkyBlue3&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="k"&gt;\rule&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\layerwidth&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="k"&gt;\layerheight&lt;/span&gt;&lt;span class="nb"&gt;}}&lt;/span&gt;
]&lt;span class="nb"&gt;{&lt;/span&gt;head.background&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\AddLayersAtBeginOfPageStyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrheadings&lt;span class="nb"&gt;}{&lt;/span&gt;head.background&lt;span class="nb"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\begin&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\title&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Titel&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\author&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;Autor&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\maketitle&lt;/span&gt;
&lt;span class="k"&gt;\blinddocument&lt;/span&gt;
&lt;span class="k"&gt;\end&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;document&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As the &lt;code&gt;plain&lt;/code&gt; page style &lt;code&gt;plain.scrheadings&lt;/code&gt; has no header content when using &lt;code&gt;scrartcl&lt;/code&gt; and the default setting of &lt;code&gt;scrlayer-scrpage&lt;/code&gt;, it would make no sense to add the header background to this page style. Therefore, the layer in the example is only added to the &lt;code&gt;headings&lt;/code&gt; style &lt;code&gt;scrheadings&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you wanted to add the layer to all layer page styles (including &lt;code&gt;empty&lt;/code&gt;!), you could simply use:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;\AddLayersAtBeginOfPageStyle&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;@everystyle@&lt;span class="nb"&gt;}{&lt;/span&gt;head.background&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Markus Kohm</dc:creator><pubDate>Tue, 08 Jul 2025 08:43:50 -0000</pubDate><guid>https://sourceforge.net069a489b384d3d8e2d770d8d16f46e7d325f5cb1</guid></item></channel></rss>