删除章节标题页上的灰色章节编号框

删除章节标题页上的灰色章节编号框

我已成功在每页的边缘添加了一个灰色框(经过小幅修改),并标明了章节编号,代码如下“在每个页边距上显示当前章节号”。我试图从每章的第一页删除章节号框,例如,如“在每个页边距上显示当前章节号的编辑框”

但是,在后一篇文章中,我找不到负责删除“第一页章节”框的代码片段。如果尝试添加\makeatletter\makeatother部分,但输出没有变化。也\cleartooddpage[\thispagestyle{empty}]不起作用。

您可以在下面找到我的代码。有什么建议吗?

\documentclass[10pt,twoside,parskip=half]{scrbook} % Document class for PhD manuscript
\linespread{1.1}
\usepackage[
   paperwidth=170mm,
   paperheight=240mm,
   top=2.5cm, bottom=3cm,
   inner=30mm, outer=25mm,
   heightrounded=true
]{geometry}

% Gray boxes for chapter numbering on pages
\usepackage[contents={},opacity=1,scale=1,color=white]{background}
\usepackage{tikzpagenodes}
\usepackage{totcount}
\usetikzlibrary{calc}

\newif\ifMaterial

\newlength\LabelSize
\setlength\LabelSize{2.5cm}
\AtBeginDocument{%
\regtotcounter{chapter}
%\setlength\LabelSize{\dimexpr\textheight/\totvalue{chapter}\relax} 
% Line above commented out as this line of code resulted in "results out of range"
\ifdim\LabelSize>2.5cm\relax
  \global\setlength\LabelSize{2.5cm}
\fi
}

\newcommand\AddLabels{%
    \Materialtrue%
    \AddEverypageHook{%
        \ifMaterial%
        \ifodd\value{page} %
        \backgroundsetup{
          angle=90, position={current page.east|-current page text area.north  east},
          vshift=8pt, hshift=-\thechapter*\LabelSize,
          contents={%
          \tikz\node[fill=gray!30,anchor=west,text width=\LabelSize,
            align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};  }%
        }
         \else
         \backgroundsetup{
          angle=90, position={current page.west|-current page text area.north west},
          vshift=-8pt, hshift=-\thechapter*\LabelSize,
          contents={%
          \tikz\node[fill=gray!30,anchor=west,text width=\LabelSize,
            align=center,text height=15pt,text depth=10pt,font=\large\sffamily] {\thechapter};  }%
         }
     \fi
     \BgMaterial%
     \else\relax\fi}%
}


\newcommand\RemoveLabels{\Materialfalse}

答案1

以下建议基于 KOMA-Script 书(德语)附录中的示例:

\documentclass[10pt,twoside,parskip=half]{scrbook} % Document class for PhD manuscript
\linespread{1.1}
\usepackage[
   paperwidth=170mm,
   paperheight=240mm,
   top=2.5cm, bottom=3cm,
   inner=30mm, outer=25mm,
   heightrounded=true
]{geometry}

\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{scrlayer-scrpage}

% the following bases on an example in the KOMA-Script book:
\newcommand*{\firstchapterthumbskip}{.1\paperheight}
\newcommand*{\lastchapterthumbskip}{\firstchapterthumbskip}
\newcommand*{\chapterthumbheight}{2em}
\newcommand*{\chapterthumbwidth}{.1\paperheight}
\newcommand*{\chapterthumbskip}{.1\paperheight}
\newcommand*{\chapterthumbboxcolor}{gray!30}
\newcommand*{\chapterthumbcolor}{black}
\newcommand*{\chapterthumbformat}{\thechapter}
\newkomafont{chapterthumb}{\normalfont\Large\sffamily\color{\chapterthumbcolor}}

\makeatletter
\newcommand*\chapterthumb@box{%
  \parbox[c][\chapterthumbheight][c]{\chapterthumbwidth}{%
      \centering\usekomafont{chapterthumb}{\chapterthumbformat}%
  }%
}
\newcommand*{\chapterthumbbox}{%
  \if@mainmatter
    \ifnum\value{chapter}>\z@
      \ifnum \value{chapterthumb}<\z@
      \else
        \begingroup
          \protected@edef\reserved@a{\chapterthumbformat}%
          \ifx\reserved@a\lastchapterthumbformat\else
            \stepcounter{chapterthumb}%
            \global\let\lastchapterthumbformat\reserved@a
          \fi
          \@tempcnta=\numexpr 
            \dimexpr 
              \paperheight
              -\firstchapterthumbskip
              -\chapterthumbwidth
              -\lastchapterthumbskip
            \relax / \dimexpr 
                       \chapterthumbskip 
                     \relax
            +1
          \relax
          \ifnum \value{chapterthumb}<\@tempcnta
          \else
            \setcounter{chapterthumb}{0}%
          \fi
          \vspace*{%
            \dimexpr 
              \firstchapterthumbskip
              + ( \chapterthumbskip )
                * \value{chapterthumb}%
              - \baselineskip
            \relax
          }\par
          \setlength{\fboxsep}{0pt}%
          \ifodd\value{page}
            \hfill
            \makebox[0pt][r]{%
              \rotatebox[origin=tr]{90}{%
                \colorbox{\chapterthumbboxcolor}{%
                  \parbox[t][\chapterthumbheight]{\chapterthumbwidth}{%
                    \chapterthumb@box
                    \vskip3mm
                  }}}}%
          \else
            \hspace*{-3mm}%
            \makebox[0pt][l]{%
              \rotatebox[origin=tr]{90}{%
                \colorbox{\chapterthumbboxcolor}{%
                  \parbox{\chapterthumbwidth}{%
                    \vskip3mm
                    \chapterthumb@box
                  }}}}%
          \fi
        \endgroup
      \fi
    \fi
  \fi
}
\makeatother

\newcounter{chapterthumb}
\setcounter{chapterthumb}{10000}
\newcommand*{\lastchapterthumbformat}{\relax}

\DeclareNewLayer[%
  background,%
  outermargin,%
  contents=\chapterthumbbox
]{chapterthumb}

\newcommand*\EnableChapterthumb{%
  \IfLayerAtPageStyle{scrheadings}{chapterthumb}{}
    {\AddLayersToPageStyle{scrheadings}{chapterthumb}}%
}
\newcommand*\DisableChapterthumb{%
  \RemoveLayersFromPageStyle{scrheadings}{chapterthumb}%
}

\EnableChapterthumb

\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\blinddocument\blinddocument\blinddocument
\blinddocument\blinddocument\blinddocument
\blinddocument\blinddocument\blinddocument
\blinddocument\blinddocument\blinddocument
\end{document}

结果:

在此处输入图片描述

相关内容