0

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}

\renewcommand\raggedchapter{\raggedright}
\setkomafont{chapter}{\Huge}
\setkomafont{chapterprefix}{\LARGE}
\newkomafont{chapternumber}{\bfseries\fontsize{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]{\dimexpr\textwidth\relax}            
            {\parbox[t][\height]{\dimexpr\textwidth\relax}{\raggedchapter{#3}}\strut}% {\raggedchapter{\leavevmode\vphantom{\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){\leavevmode\vphantom{88}};%
            \fill[headings/base,anchor=north west,rounded corners=2.5 pt]
            ([xshift=4 pt]chapternumber.north west)
            rectangle
            ([yshift=-7 pt,xshift=.33\marginparwidth+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=.33\marginparwidth+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=.33\marginparwidth+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=.33\marginparwidth+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=.33\marginparwidth+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=.33\marginparwidth+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}{}{\leavevmode\vphantom{\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}{\sffamily\normalsize}
\setkomafont{pagenumber}{\sffamily\large}
\clearpairofpagestyles

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

    \renewcommand\chaptermark[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{\ }\thechapter\autodot\enskip}{}% taken from scrguide
%   }

    \renewcommand\sectionmark[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}{\thesection\autodot\enskip}{}% 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.5\vrulewidth]
    ([xshift=-\marginparsep+.5\vrulewidth] current page header area.south west)
    rectangle
    ([xshift=-\marginparsep-.5\vrulewidth,yshift=\baselineskip] current page header area.south west);
    \node[headings/base,anchor=south east] at ([xshift=-2\marginparsep] current page header area.south west){\ifnumbered{chapter}{\leavevmode\vphantom{\headmark\strut}\chaptermarkformat}{\leavevmode\vphantom{\headmark\strut}}};
    \node[headings/base,anchor=south west] at (current page header area.south west){\headmark\strut};
\end{tikzpicture}
%   }%  IDEA 2 (part 2)
%   {%
%       \begin{tikzpicture}[overlay,remember picture]
%           \fill[headings/base,color=black,anchor=south east,rounded corners=0.5\vrulewidth]
%           ([xshift=-\marginparsep+.5\vrulewidth] current page header area.south west)
%           rectangle
%           ([xshift=-\marginparsep-.5\vrulewidth,yshift=\baselineskip] current page header area.south west);
%%          \node[headings/base,anchor=south east] at ([xshift=-2\marginparsep] current page header area.south west){\ifnumbered{chapter}{\leavevmode\vphantom{\headmark\strut}\chaptermarkformat}{\leavevmode\vphantom{\headmark\strut}}};
%           \node[headings/base,anchor=south west] at (current page header area.south west){\headmark\strut};
%       \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.5\vrulewidth]
        ([xshift=\marginparsep-.5\vrulewidth] current page header area.south east)
        rectangle
        ([xshift=\marginparsep+.5\vrulewidth,yshift=\baselineskip] current page header area.south east);
        \node[headings/base,anchor=south west] at ([xshift=2\marginparsep] current page header area.south east){\ifnumbered{section}{\leavevmode\vphantom{\headmark\strut}\sectionmarkformat}{\leavevmode\vphantom{\headmark\strut}}};
        \node[headings/base,anchor=south east] at (current page header area.south east){\headmark\strut};
    \end{tikzpicture}
}
\lefoot*{%
    \begin{tikzpicture}[overlay,remember picture]
        \fill[headings/base,color=black,anchor=south east,rounded corners=0.5\vrulewidth]
        ([xshift=-\marginparsep+.5\vrulewidth] current page footer area.south west)
        rectangle
        ([xshift=-\marginparsep-.5\vrulewidth,yshift=-3\baselineskip] current page footer area.south west);
        \node[headings/base,anchor=south east] at ([xshift=-2\marginparsep,yshift=-3\baselineskip] current page footer area.south west){\pagemark\strut};
    \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.5\vrulewidth]
        ([xshift=\marginparsep-.5\vrulewidth] current page footer area.south east)
        rectangle
        ([xshift=\marginparsep+.5\vrulewidth,yshift=-3\baselineskip] current page footer area.south east);
        \node[headings/base,anchor=south west] at ([xshift=2\marginparsep,yshift=-3\baselineskip] current page footer area.south east){\pagemark\strut};
    \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[-\dp\strutbox]{\vrulewidth}{\baselineskip}% Linie -- Offset,Breite,Höhe
%                   \hspace*{\marginparsep}% Abstand
%               }{}%
%           }% 
%           #1% Text 
%       }{%
%           #1%Text 
%           \makebox[0pt][l]{%
%               \hspace*{\marginparsep}% Abstand 
%               \ifnumbered{chapter}{%
%                   \rule[-\dp\strutbox]{\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[-\dp\strutbox]{\vrulewidth}{\baselineskip}% Linie -- Offset,Breite,Höhe
%                   \enskip% Abstand 
%                   \sectionmarkformat% Abschnittsnummer 
%               }{}%
%           }% 
%       }% 
%   } 
%   \ohead{\headmark} 
%   \rofoot*{%
%       \makebox[0pt][l]{%
%           \hspace{\marginparsep}%  
%           \raisebox{0pt}[\ht\strutbox][\dp\strutbox]{% 
%               \rule[-\dp\strutbox]{\vrulewidth}{2\baselineskip}% Linie -- Offset,Breite,Höhe
%           }% 
%           \enskip 
%           \pagemark 
%       }% 
%   }
%   \lefoot*{%
%       \makebox[0pt][r]{% 
%           \pagemark 
%           \enskip
%           \raisebox{0pt}[\ht\strutbox][\dp\strutbox]{% 
%               \rule[-\dp\strutbox]{\vrulewidth}{2\baselineskip}% 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.

0

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[-\dp\strutbox]{\vrulewidth}{\baselineskip}% Linie -- Offset,Breite,Höhe
                    \hspace*{\marginparsep}% Abstand
                }{}%
            }% 
            #1% Text 
        }{%
            #1%Text 
            \makebox[0pt][l]{%
                \hspace*{2\marginparsep}% Abstand 
                \ifnumbered{chapter}{%
%                   \rule[-\dp\strutbox]{\vrulewidth}{\baselineskip}% Linie -- Offset,Breite,Höhe
%                   \enskip% Abstand 
                    \chaptermarkformat% Kapitelnummer
                }{}%
            }% 
        }% 
    } 
    \renewcommand*{\sectionmark}[1]{% 
        \markright{% 
            #1%Text 
            \makebox[0pt][l]{% 
                \ifnumbered{section}{%
                    \hspace{2\marginparsep}% Abstand 
%                   \rule[-\dp\strutbox]{\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.5\vrulewidth]
            ([xshift=-\marginparsep+.5\vrulewidth] current page header area.south west)
            rectangle
            ([xshift=-\marginparsep-.5\vrulewidth,yshift=\baselineskip] current page header area.south west);
%           \node[headings/base,anchor=south east] at ([xshift=-2\marginparsep] current page header area.south west){\leavevmode\vphantom{\headmark\strut}\chaptermarkformat};
            \node[headings/base,anchor=south west] at (current page header area.south west){\headmark\strut};
        \end{tikzpicture}
}
\rohead{%
    \begin{tikzpicture}[overlay,remember picture]
        \fill[headings/base,color=black,anchor=south west,rounded corners=0.5\vrulewidth]
        ([xshift=\marginparsep-.5\vrulewidth] current page header area.south east)
        rectangle
        ([xshift=\marginparsep+.5\vrulewidth,yshift=\baselineskip] current page header area.south east);
%       \node[headings/base,anchor=south west] at ([xshift=2\marginparsep] current page header area.south east){\leavevmode\vphantom{\headmark\strut}\sectionmarkformat};
        \node[headings/base,anchor=south east] at (current page header area.south east){\headmark\strut};
    \end{tikzpicture}
}
\lefoot*{%
    \begin{tikzpicture}[overlay,remember picture]
        \fill[headings/base,color=black,anchor=south east,rounded corners=0.5\vrulewidth]
        ([xshift=-\marginparsep+.5\vrulewidth] current page footer area.south west)
        rectangle
        ([xshift=-\marginparsep-.5\vrulewidth,yshift=-3\baselineskip] current page footer area.south west);
        \node[headings/base,anchor=south east] at ([xshift=-2\marginparsep,yshift=-3\baselineskip] current page footer area.south west){\pagemark\strut};
    \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.5\vrulewidth]
        ([xshift=\marginparsep-.5\vrulewidth] current page footer area.south east)
        rectangle
        ([xshift=\marginparsep+.5\vrulewidth,yshift=-3\baselineskip] current page footer area.south east);
        \node[headings/base,anchor=south west] at ([xshift=2\marginparsep,yshift=-3\baselineskip] current page footer area.south east){\pagemark\strut};
    \end{tikzpicture}%
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.