我正在使用 制作参考手册scrbook
。我想在每页外边缘添加一个“标签”,在 1.5 厘米的灰色矩形中显示当前章节号。矩形内是当前章节号。这样读者就可以通过查看印刷书籍的边缘快速找到特定章节的开头。
作为一项额外的挑战,章节标签需要随着章节号的增加而向下移动。例如,在第 1 章中,章节标签将位于页面顶部 1 厘米处;对于第 2 章,它将位于页面顶部 2.5 厘米处(1 厘米空白,加上前一个章节标签的高度 1.5 厘米),依此类推。
这可能吗?如果可以,如何实现?
答案1
以下是使用background
包(根据需要更改设置)。使用\AddLabels
选项卡激活;\RemoveLabels
停用选项卡:
\documentclass[openany]{scrbook}
\usepackage[contents={},opacity=1,scale=1,color=black]{background}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{tikzpagenodes}
\usepackage{totcount}
\usepackage{lipsum}% just to generate text for the example
\usetikzlibrary{calc}
\newif\ifMaterial
\newlength\LabelSize
\setlength\LabelSize{2.5cm}
\AtBeginDocument{%
\regtotcounter{chapter}
\setlength\LabelSize{\dimexpr\textheight/\totvalue{chapter}\relax}
\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=15pt,
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=-15pt,
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}
\begin{document}
\chapter{Test Chapter One}
\AddLabels
\lipsum[1-2]
\chapter{Test Chapter Two}
\lipsum[1-2]
\chapter{Test Chapter Three}
\lipsum[1-2]
\chapter{Test Chapter Four}
\lipsum[1-2]
\chapter{Test Chapter Five}
\RemoveLabels
\lipsum[1-2]
\end{document}
答案2
答案3
以下建议基于 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{@everystyle@}{chapterthumb}}%
}
\newcommand*\DisableChapterthumb{%
\RemoveLayersFromPageStyle{@everystyle@}{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}
结果: