<?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_HeaderSeparateNumberText</title><link>https://sourceforge.net/p/koma-script/wiki-en/HowTo_HeaderSeparateNumberText/</link><description>Recent changes to HowTo_HeaderSeparateNumberText</description><atom:link href="https://sourceforge.net/p/koma-script/wiki-en/HowTo_HeaderSeparateNumberText/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 03 Jun 2025 06:58:36 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/koma-script/wiki-en/HowTo_HeaderSeparateNumberText/feed" rel="self" type="application/rss+xml"/><item><title>HowTo_HeaderSeparateNumberText modified by Markus Kohm</title><link>https://sourceforge.net/p/koma-script/wiki-en/HowTo_HeaderSeparateNumberText/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="how-to-display-the-chapter-number-on-the-outside-and-the-chapter-title-on-the-inside-of-the-page-header"&gt;How to display the chapter number on the outside and the chapter title on the inside of the page header&lt;/h1&gt;
&lt;p&gt;Most classes use &lt;code&gt;\chaptermark&lt;/code&gt; to set the marks for the living column title, i.e. usually the page header. With &lt;code&gt;scrreprt&lt;/code&gt;, the default definition is in the page style headings:&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;\renewcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermark&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\if@twoside\expandafter\markboth\else\expandafter\markright\fi&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="k"&gt;\Ifnumbered&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;chapter&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
      &lt;span class="k"&gt;\MakeMarkcase&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
    &lt;span class="nb"&gt;}{}&lt;/span&gt;&lt;span class="k"&gt;\MakeMarkcase&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;#1&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="nb"&gt;}{}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With &lt;code&gt;scrbook&lt;/code&gt;, there is additionally a test for the main matter (&lt;code&gt;\mainmatter&lt;/code&gt;). When using &lt;code&gt;scrlayer-scrpage&lt;/code&gt;, the definition looks a little more complicated, but also boils down to the fact that the number (defined in &lt;code&gt;\chaptermarkformat&lt;/code&gt;) is output before the title text (in &lt;code&gt;#1&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;If you wanted to set the number left-aligned and the title right-aligned, you could simply start at &lt;code&gt;\chaptermarkformat&lt;/code&gt; and in its definition:&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;\newcommand*\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chapappifchapterprefix&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\&lt;/span&gt; &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\thechapter\autodot\enskip&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and replace the distance of half a square &lt;code&gt;\enskip&lt;/code&gt; with an infinitely stretchable distance &lt;code&gt;\hspace{.5em plus 1fill}&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;\renewcommand*\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chapappifchapterprefix&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\&lt;/span&gt; &lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\thechapter\autodot\hspace&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;.5em plus 1fill&lt;span class="nb"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;However, we want the position of the number and text to be swapped on right-hand (=odd) pages of a double-sided document. We therefore need a new instruction that does exactly that:&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="na"&gt;[headsepline]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrbook&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="na"&gt;[english]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;babel&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;\DeclareRobustCommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[2]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\ifodd\value&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;page&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% This only works in the head or foot, otherwise \ifthispageodd is needed instead!!!&lt;/span&gt;
    #2&lt;span class="k"&gt;\hfill&lt;/span&gt; #1&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\else&lt;/span&gt;
    #1&lt;span class="k"&gt;\hfill&lt;/span&gt; #2&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\fi&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\renewcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermark&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\csname&lt;/span&gt; @mkboth&lt;span class="k"&gt;\endcsname&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\MakeMarkcase&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}}}&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\MakeMarkcase&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}}}&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\renewcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\sectionmark&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1]&lt;span class="nb"&gt;{}&lt;/span&gt;&lt;span class="c"&gt;% \section should not change any mark&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;\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;It is important to use &lt;code&gt;\DeclareRobustCommand&lt;/code&gt; (or alternatively &lt;code&gt;\NewDocumentCommand&lt;/code&gt;) so that the command does not expand too early. If &lt;code&gt;\newcommand&lt;/code&gt; is used, the test as to whether the page is even or odd would take place when the marker is set within &lt;code&gt;\chapter&lt;/code&gt; and not only when it is used.&lt;/p&gt;
&lt;p&gt;Of course, this also works when using &lt;code&gt;scrlayer-scrpage&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="na"&gt;[headsepline]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;scrbook&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="na"&gt;[english]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;babel&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;\usepackage&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;\automark&lt;/span&gt;&lt;span class="na"&gt;[chapter]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;chapter&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\NewDocumentCommand&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;m+m&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\ifodd\value&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;page&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% This only works in the head or foot, otherwise \ifthispageodd is needed instead!!!&lt;/span&gt;
    #2&lt;span class="k"&gt;\hfill&lt;/span&gt; #1&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\else&lt;/span&gt;
    #1&lt;span class="k"&gt;\hfill&lt;/span&gt; #2&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\fi&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\renewcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermark&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\csname&lt;/span&gt; @mkboth&lt;span class="k"&gt;\endcsname&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\MakeMarkcase&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}}}&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\MakeMarkcase&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}}}&lt;/span&gt;
&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;\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;It also works with &lt;code&gt;scrlayer-scrpage&lt;/code&gt; and a standard class, but then you have to move the page number from the header to the footer, otherwise it will overlap with either the number or the text of the chapter marker:&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="na"&gt;[headsepline]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;book&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="na"&gt;[english]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;babel&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;\usepackage&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;\automark&lt;/span&gt;&lt;span class="na"&gt;[chapter]&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;chapter&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\clearpairofpagestyles&lt;/span&gt;
&lt;span class="k"&gt;\ohead&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\headmark&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\ofoot*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\pagemark&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\NewDocumentCommand&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;m+m&lt;span class="nb"&gt;}{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\ifodd\value&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;page&lt;span class="nb"&gt;}&lt;/span&gt;&lt;span class="c"&gt;% This only works in the head or foot, otherwise \ifthispageodd is needed instead!!!&lt;/span&gt;
    #2&lt;span class="k"&gt;\hfill&lt;/span&gt; #1&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\else&lt;/span&gt;
    #1&lt;span class="k"&gt;\hfill&lt;/span&gt; #2&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\fi&lt;/span&gt;
&lt;span class="nb"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\renewcommand*&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermark&lt;/span&gt;&lt;span class="nb"&gt;}&lt;/span&gt;[1]&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="c"&gt;%&lt;/span&gt;
  &lt;span class="k"&gt;\csname&lt;/span&gt; @mkboth&lt;span class="k"&gt;\endcsname&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\MakeMarkcase&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}}}&lt;/span&gt;
  &lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\MakeMarkcase&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\FlipNumberText&lt;/span&gt;&lt;span class="nb"&gt;{&lt;/span&gt;&lt;span class="k"&gt;\chaptermarkformat&lt;/span&gt;&lt;span class="nb"&gt;}{&lt;/span&gt;#1&lt;span class="nb"&gt;}}}&lt;/span&gt;
&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;\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;By the way, I only used the &lt;code&gt;headsepline&lt;/code&gt; option in the examples to make the header area better distinguishable. What the &lt;code&gt;\MakeMarkcase&lt;/code&gt; is all about can be found in the KOMA-Script user manuals.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Markus Kohm</dc:creator><pubDate>Tue, 03 Jun 2025 06:58:36 -0000</pubDate><guid>https://sourceforge.netce35536d5b9e58ccef958b900a09935d88cb2956</guid></item></channel></rss>