TransWikia.com

Remove Zero as Chapter Number in Header Using scrlayer-scrpage

TeX - LaTeX Asked on April 12, 2021

I am currently working on a layout for a document (based on this post and this), using scrbook with scrlayer-scrpage.

After a long struggle to get lines with rounded corners in the header and footer, everything works as expected — except the numbering of the table of contents in the header. For some reason that I do not understand (I am sure because lack of basic knowledge) it gets a chapter number 0 and section number 0.0, instead of an empty field, which is the desired output for unnumbered chapters.

When I compile my document with the slightly modified original code for the header no numbers are given for the table of contents.

Based on this, my idea was to use ifnumbered{chapter}{THEN}{ELSE}, either by redefining chaptermarkformat and sectionmarkformat (IDEA 1) or by changing the output for lehead{} (and rohead{} IDEA 2). What am I missing? Any help is much appreciated. Thank you in advance.

Here is the code containing my approaches and the modified original code for the header and footer for camparison:

documentclass[12pt,paper=a4,DIV=calc,parskip=off,numbers=noenddot,chapterprefix=false]{scrbook} 

usepackage[utf8]{inputenc}
usepackage{lmodern}
usepackage[ngerman]{babel}
usepackage[T1]{fontenc}
usepackage{calc}

usepackage[dvipsnames]{xcolor}

usepackage[inner=1.5cm,outer=3.0cm,top=1.5cm,bottom=2cm,headheight=8mm,headsep=1cm,footskip=1cm,includeheadfoot]{geometry} % ,showframe
setlength{marginparwidth}{2.77cm}
setlength{marginparsep}{.2cm}

usepackage[onehalfspacing]{setspace}

% Chapter Title Layout -------------------------------------------------
% BASED ON: https://tex.stackexchange.com/questions/423091/chapter-heading-designs-in-koma-script
usepackage{tikz}
usetikzlibrary{positioning, backgrounds}
usepackage[outline]{contour}
    contourlength{1.25pt}
usepackage{tikzpagenodes}

renewcommandraggedchapter{raggedright}
setkomafont{chapter}{Huge}
setkomafont{chapterprefix}{LARGE}
newkomafont{chapternumber}{bfseriesfontsize{75pt}{75pt}selectfont}

tikzset{
    headings/base/.style = {
        outer sep = 0pt,
        inner sep = 0pt,
        %draw, rectangle    % just for testing purposes
    },
    headings/chapterbackground/.style = {
        headings/base,
        % if shades are to be used (gave ugly results for the shading):
        %      shade,
        %      left color = white,
        %      right color = black,
        % without shades:
        color = black
    },
    headings/chapapp/.style = {
        headings/base,
        text = black,
        font = usekomafont{chapterprefix}
    },
    headings/chapternumber/.style= { 
        headings/base,
        text = black,
        font = usekomafont{chapternumber}
    }
}

makeatletter
renewcommand*chapterlinesformat[3]{%
    ifstr{#1}{chapter}{%
        begin{tikzpicture}[baseline=(title.base)]
        node[headings/base,anchor=center](title){%
            parbox[t]{dimexprtextwidthrelax}            
            {parbox[t][height]{dimexprtextwidthrelax}{raggedchapter{#3}}strut}% {raggedchapter{leavevmodevphantom{textbf{Ôp'}}#3}} //orig: {raggedchapter #3}
        };
        % chapter number
        ifstr{#2}{}
        {   % a phantom chapternumber is set to achieve the same vertical spacing for toc and other unnumbered chapters as for numbered chapters
            node(chapternumber)[anchor=south west,headings/chapternumber]
            at([yshift=-14.5pt] title.north east){leavevmodevphantom{88}};%
            fill[headings/base,anchor=north west,rounded corners=2.5 pt]
            ([xshift=4 pt]chapternumber.north west)
            rectangle
            ([yshift=-7 pt,xshift=.33marginparwidth+4 pt]chapternumber.north west);%
            fill[headings/base,color=black!85,anchor=north west,rounded corners=2.5 pt]
            ([yshift=-9 pt,xshift=5.5pt]chapternumber.north west)
            rectangle
            ([yshift=-16 pt,xshift=.33marginparwidth+5.5pt]chapternumber.north west);%
            fill[headings/base,color=black!70,anchor=north west,rounded corners=2.5 pt]
            ([yshift=-18 pt,xshift=9pt]chapternumber.north west)
            rectangle
            ([yshift=-25 pt,xshift=.33marginparwidth+9pt]chapternumber.north west);%
            fill[headings/base,color=black!50,anchor=north west,rounded corners=2.5 pt]
            ([yshift=-27 pt,xshift=16.5pt]chapternumber.north west)
            rectangle
            ([yshift=-34 pt,xshift=.33marginparwidth+16.5pt]chapternumber.north west);%
            fill[headings/base,color=black!20,anchor=north west,rounded corners=2.5 pt]
            ([yshift=-36 pt,xshift=30pt]chapternumber.north west)
            rectangle
            ([yshift=-43 pt,xshift=.33marginparwidth+30pt]chapternumber.north west);%
            fill[headings/base,color=black!10,anchor=north west,rounded corners=2.5 pt]
            ([yshift=-45 pt,xshift=52pt]chapternumber.north west)
            rectangle
            ([yshift=-52 pt,xshift=.33marginparwidth+52pt]chapternumber.north west);%
        }
        {   % number definition for numbered chapters
            node(chapternumber)[anchor=south west,headings/chapternumber]
            at([yshift=-14.5pt] title.north east){#2};%
        }
        % decorative element(s)
        ifstr{#2}{}{}{
            fill[headings/chapterbackground,anchor=east,rounded corners=1 pt]
            ([yshift=11.5 pt]title.north east)
            rectangle
            ([yshift=13.5 pt,xshift=4.2 cm]title.north);%
        }
        % chapter prefix
        node(chapapp)[headings/chapapp,anchor=north east]
        at (chapternumber.north west){ifstr{#2}{}{leavevmodevphantom{contour{white}chapapp}}{contour{white}chapapp}strut};% 
        end{tikzpicture}
        par
    }{%
        @hangfrom{#2}{#3}% other section levels using style=chapter
    }%
}
makeatother

% Header and Footer Layout --------------------------------
usepackage[automark]{scrlayer-scrpage}
setkomafont{pageheadfoot}{footnotesize}
setkomafont{pagehead}{sffamilynormalsize}
setkomafont{pagenumber}{sffamilylarge}
clearpairofpagestyles

    newlength{vrulewidth}
        setlength{vrulewidth}{1.25 pt}

    renewcommandchaptermark[1]{%
        markboth{ifnumbered{chapter}{#1}{#1}}{ifnumbered{chapter}{#1}{#1}}%
    }

    % IDEA 1: Supposed to remove chapternumber from header in table of contents -- does not
%   renewcommand*{chaptermarkformat}{%
%       ifnumbered{chapter}{chapappifchapterprefix{ }thechapterautodotenskip}{}% taken from scrguide
%   }

    renewcommandsectionmark[1]{%
        markright{ifnumbered{section}{#1}{#1}}%
    }

    % IDEA 1 (part 2): Supposed to remove sectionumber from header in table of contents -- does not
%   renewcommand*{sectionmarkformat}{%
%       ifnumbered{section}{thesectionautodotenskip}{}% taken from scrguide
%   }

lehead{%
%   ifnumbered{chapter}{% IDEA 2: Supposed to remove chapternumber from header in table of contents -- does not
begin{tikzpicture}[overlay,remember picture]
    fill[headings/base,color=black,anchor=south east,rounded corners=0.5vrulewidth]
    ([xshift=-marginparsep+.5vrulewidth] current page header area.south west)
    rectangle
    ([xshift=-marginparsep-.5vrulewidth,yshift=baselineskip] current page header area.south west);
    node[headings/base,anchor=south east] at ([xshift=-2marginparsep] current page header area.south west){ifnumbered{chapter}{leavevmodevphantom{headmarkstrut}chaptermarkformat}{leavevmodevphantom{headmarkstrut}}};
    node[headings/base,anchor=south west] at (current page header area.south west){headmarkstrut};
end{tikzpicture}
%   }%  IDEA 2 (part 2)
%   {%
%       begin{tikzpicture}[overlay,remember picture]
%           fill[headings/base,color=black,anchor=south east,rounded corners=0.5vrulewidth]
%           ([xshift=-marginparsep+.5vrulewidth] current page header area.south west)
%           rectangle
%           ([xshift=-marginparsep-.5vrulewidth,yshift=baselineskip] current page header area.south west);
%%          node[headings/base,anchor=south east] at ([xshift=-2marginparsep] current page header area.south west){ifnumbered{chapter}{leavevmodevphantom{headmarkstrut}chaptermarkformat}{leavevmodevphantom{headmarkstrut}}};
%           node[headings/base,anchor=south west] at (current page header area.south west){headmarkstrut};
%       end{tikzpicture}
%   }
}

rohead{% (IDEA 2 did not work for lehead)
    begin{tikzpicture}[overlay,remember picture]
        fill[headings/base,color=black,anchor=south west,rounded corners=0.5vrulewidth]
        ([xshift=marginparsep-.5vrulewidth] current page header area.south east)
        rectangle
        ([xshift=marginparsep+.5vrulewidth,yshift=baselineskip] current page header area.south east);
        node[headings/base,anchor=south west] at ([xshift=2marginparsep] current page header area.south east){ifnumbered{section}{leavevmodevphantom{headmarkstrut}sectionmarkformat}{leavevmodevphantom{headmarkstrut}}};
        node[headings/base,anchor=south east] at (current page header area.south east){headmarkstrut};
    end{tikzpicture}
}
lefoot*{%
    begin{tikzpicture}[overlay,remember picture]
        fill[headings/base,color=black,anchor=south east,rounded corners=0.5vrulewidth]
        ([xshift=-marginparsep+.5vrulewidth] current page footer area.south west)
        rectangle
        ([xshift=-marginparsep-.5vrulewidth,yshift=-3baselineskip] current page footer area.south west);
        node[headings/base,anchor=south east] at ([xshift=-2marginparsep,yshift=-3baselineskip] current page footer area.south west){pagemarkstrut};
    end{tikzpicture}%
}
rofoot*{% funktioniert ohne * nur auf nicht chapter-Seiten
    begin{tikzpicture}[overlay,remember picture]
        fill[headings/base,color=black,anchor=south west,rounded corners=0.5vrulewidth]
        ([xshift=marginparsep-.5vrulewidth] current page footer area.south east)
        rectangle
        ([xshift=marginparsep+.5vrulewidth,yshift=-3baselineskip] current page footer area.south east);
        node[headings/base,anchor=south west] at ([xshift=2marginparsep,yshift=-3baselineskip] current page footer area.south east){pagemarkstrut};
    end{tikzpicture}%
}

    % https://tex.stackexchange.com/questions/272824/pagenumbers-headers-with-vertical-lines-style
    %% here there are no numbers for the table of contents in the headings -- numbering in TOC as desired
%   renewcommand*{chaptermark}[1]{% 
%       markboth{% 
%           makebox[0pt][r]{%
%               ifnumbered{chapter}{%
%                   chaptermarkformat% Kapitelnummer 
%                   %enskip% Abstand -- wird zu groß, wenn nicht auskommentiert
%                   rule[-dpstrutbox]{vrulewidth}{baselineskip}% Linie -- Offset,Breite,Höhe
%                   hspace*{marginparsep}% Abstand
%               }{}%
%           }% 
%           #1% Text 
%       }{%
%           #1%Text 
%           makebox[0pt][l]{%
%               hspace*{marginparsep}% Abstand 
%               ifnumbered{chapter}{%
%                   rule[-dpstrutbox]{vrulewidth}{baselineskip}% Linie -- Offset,Breite,Höhe
%                   enskip% Abstand 
%                   chaptermarkformat% Kapitelnummer
%               }{}%
%           }% 
%       }% 
%   } 
%   renewcommand*{sectionmark}[1]{% 
%       markright{% 
%           #1%Text 
%           makebox[0pt][l]{% 
%               ifnumbered{section}{%
%                   hspace{marginparsep}% Abstand 
%                   rule[-dpstrutbox]{vrulewidth}{baselineskip}% Linie -- Offset,Breite,Höhe
%                   enskip% Abstand 
%                   sectionmarkformat% Abschnittsnummer 
%               }{}%
%           }% 
%       }% 
%   } 
%   ohead{headmark} 
%   rofoot*{%
%       makebox[0pt][l]{%
%           hspace{marginparsep}%  
%           raisebox{0pt}[htstrutbox][dpstrutbox]{% 
%               rule[-dpstrutbox]{vrulewidth}{2baselineskip}% Linie -- Offset,Breite,Höhe
%           }% 
%           enskip 
%           pagemark 
%       }% 
%   }
%   lefoot*{%
%       makebox[0pt][r]{% 
%           pagemark 
%           enskip
%           raisebox{0pt}[htstrutbox][dpstrutbox]{% 
%               rule[-dpstrutbox]{vrulewidth}{2baselineskip}% Linie -- Offset,Breite,Höhe 
%           }% 
%           hspace{marginparsep}%
%       }% 
%   }

usepackage{blindtext}

usepackage[raiselinks,colorlinks,bookmarks,pageanchor,hyperindex]{hyperref}
hypersetup{linkcolor=RoyalBlue}

begin{document}
    markboth{Inhaltsverzeichnis}{Inhaltsverzeichnis}
    setcounter{page}{1}
    pagenumbering{Roman}
        tableofcontents
    setcounter{tocdepth}{3}
    clearpage
    setcounter{page}{1}
    pagenumbering{arabic}
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
        Blinddocument
    appendix
        Blinddocument
end{document}

Edit: here are some images to visualize the differences:
original Chapter lehead
original Chapter rohead
original TOC lehead
original TOC rohead
Chapter Start
TOC Start
Chapter lehead -- intended output
Chapter rohead -- intended output
TOC lehead -- unwanted number
TOC rohead -- unwanted number

EDIT: I just figured out (here) that the problem is that ifnumbered{chapter} checks the value of secnumdepth which is not altered in the header, as far as I understood, and a redefinition of chaptermark is needed. My redefinition is obviously not enough for the intended result.

One Answer

Here is a solution that merges the original rule based approach with tikzpictures. I left the original parts as comments. I am still wondering if there is a fully tikz-based approach, though.

    renewcommand*{chaptermark}[1]{% 
        markboth{% 
            makebox[0pt][r]{%
                ifnumbered{chapter}{%
                    chaptermarkformat% Kapitelnummer 
                    %enskip% Abstand -- wird zu groß, wenn nicht auskommentiert
%                   rule[-dpstrutbox]{vrulewidth}{baselineskip}% Linie -- Offset,Breite,Höhe
                    hspace*{marginparsep}% Abstand
                }{}%
            }% 
            #1% Text 
        }{%
            #1%Text 
            makebox[0pt][l]{%
                hspace*{2marginparsep}% Abstand 
                ifnumbered{chapter}{%
%                   rule[-dpstrutbox]{vrulewidth}{baselineskip}% Linie -- Offset,Breite,Höhe
%                   enskip% Abstand 
                    chaptermarkformat% Kapitelnummer
                }{}%
            }% 
        }% 
    } 
    renewcommand*{sectionmark}[1]{% 
        markright{% 
            #1%Text 
            makebox[0pt][l]{% 
                ifnumbered{section}{%
                    hspace{2marginparsep}% Abstand 
%                   rule[-dpstrutbox]{vrulewidth}{baselineskip}% Linie -- Offset,Breite,Höhe
%                   enskip% Abstand 
                    sectionmarkformat% Abschnittsnummer 
                }{}%
            }% 
        }% 
    }

lehead{%
        begin{tikzpicture}[overlay,remember picture]
            fill[headings/base,color=black,anchor=south east,rounded corners=0.5vrulewidth]
            ([xshift=-marginparsep+.5vrulewidth] current page header area.south west)
            rectangle
            ([xshift=-marginparsep-.5vrulewidth,yshift=baselineskip] current page header area.south west);
%           node[headings/base,anchor=south east] at ([xshift=-2marginparsep] current page header area.south west){leavevmodevphantom{headmarkstrut}chaptermarkformat};
            node[headings/base,anchor=south west] at (current page header area.south west){headmarkstrut};
        end{tikzpicture}
}
rohead{%
    begin{tikzpicture}[overlay,remember picture]
        fill[headings/base,color=black,anchor=south west,rounded corners=0.5vrulewidth]
        ([xshift=marginparsep-.5vrulewidth] current page header area.south east)
        rectangle
        ([xshift=marginparsep+.5vrulewidth,yshift=baselineskip] current page header area.south east);
%       node[headings/base,anchor=south west] at ([xshift=2marginparsep] current page header area.south east){leavevmodevphantom{headmarkstrut}sectionmarkformat};
        node[headings/base,anchor=south east] at (current page header area.south east){headmarkstrut};
    end{tikzpicture}
}
lefoot*{%
    begin{tikzpicture}[overlay,remember picture]
        fill[headings/base,color=black,anchor=south east,rounded corners=0.5vrulewidth]
        ([xshift=-marginparsep+.5vrulewidth] current page footer area.south west)
        rectangle
        ([xshift=-marginparsep-.5vrulewidth,yshift=-3baselineskip] current page footer area.south west);
        node[headings/base,anchor=south east] at ([xshift=-2marginparsep,yshift=-3baselineskip] current page footer area.south west){pagemarkstrut};
    end{tikzpicture}%
}
rofoot*{% funktioniert ohne * nur auf nicht chapter-Seiten
    begin{tikzpicture}[overlay,remember picture]
        fill[headings/base,color=black,anchor=south west,rounded corners=0.5vrulewidth]
        ([xshift=marginparsep-.5vrulewidth] current page footer area.south east)
        rectangle
        ([xshift=marginparsep+.5vrulewidth,yshift=-3baselineskip] current page footer area.south east);
        node[headings/base,anchor=south west] at ([xshift=2marginparsep,yshift=-3baselineskip] current page footer area.south east){pagemarkstrut};
    end{tikzpicture}%
}

Answered by Echo on April 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP