使用 scrlayer-scrpage 删除标题中的章节号零

使用 scrlayer-scrpage 删除标题中的章节号零

我目前正在设计一个文档的布局(基于这个帖子),使用 scrbook 和 scrlayer-scrpage。

经过长时间的努力,终于在页眉和页脚中得到了圆角线条,一切都按预期工作了——除了页眉中目录的编号。由于某种我无法理解的原因(我确信是因为缺乏基础知识),它得到的是章节号 0 和节号 0.0,而不是一个空字段,这是无编号章节所需的输出。

当我用稍加修改的标头的原始代码目录中未提供编号。

基于此,我的想法是使用\ifnumbered{chapter}{THEN}{ELSE},要么重新定义\chaptermarkformat和(想法 1),要么更改(和想法 2)\sectionmarkformat的输出。我遗漏了什么?任何帮助都非常感谢。提前谢谢您。\lehead{}\rohead{}

下面是包含我的方法的代码以及用于比较的页眉和页脚的修改后的原始代码:

\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}

编辑:这里有一些图像可以直观地显示差异: 原章 lehead 原章rohead 原始 TOC lehead 原装 TOC 罗赫 章节开始 目录开始 第 lehead 章 -- 预期输出 第 rohead 章--预期输出 TOC lehead -- 不需要的号码 TOC rohead -- 不需要的号码

编辑:我刚刚发现(这里) 问题在于\ifnumbered{chapter}检查 secnumdepth 的值,据我所知,该值在标题中没有改变,需要重新定义 chaptermark。我的重新定义显然不足以达到预期结果。

答案1

这是一个将原始\rule方法与 tikzpictures 合并的解决方案。我将原始部分保留为注释。不过,我仍然想知道是否存在完全基于 tikz 的方法。

    \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}%
}

相关内容