我想在我的文档中添加一个缩略图索引,即右侧的一个小矩形。这在浏览打印文档时很有用。我认为它看起来也很漂亮。
有多个软件包可用于实现此目标。我想使用fancytabs
。
我设置了 MWE。然而,事实证明目录也被视为章节,并且也获得了缩略索引 #0。
我怎样才能省略第一个拇指索引?
手册中提到了该\fancytabsFloor
命令,我以为它是为此设计的。但是设置了这个命令,并没有解决问题。
CTAN 软件包花样标签:https://ctan.org/pkg/fancytabs
Overleaf 编辑器上的 MWE:https://v2.overleaf.com/5747617328trvpfsmswrhc
梅威瑟:
\documentclass{scrbook}
% changed scrpage2 from fancytabs documentation example to the newer scrlayer-scrpage package
\usepackage{scrlayer-scrpage}
\usepackage{fancytabs}
\usepackage{lipsum}
\fancytabsHeight{1.5cm}
%\fancytabsGap{}
%Define the maximum amount of tabs on a page. After \tabcount tabs are displayed, the next tab is displayed on top of the page again.
\fancytabsCount{6}
\fancytabsLeftColor{gray!50}
\fancytabsRightColor{gray!50}
\fancytabsRotate{0}
\fancytabsFloor{0}
% Set central right header to display tab
% for both scrplain and scrheadings
\cohead[\fancytab{\color{white}\thechapter}{\thechapter}]{\fancytab{\color{white}\thechapter}{\thechapter}}
\begin{document}
\tableofcontents{}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\end{document}
答案1
您正在使用包scrlayer-scrpage
。因此,我将为章节缩略图声明一个新层:
\DeclareNewLayer[
background,
oddpage,
contents={\fancytab{\color{white}\thechapter}{\thechapter}}
]{fancytab.odd}
然后我将分别对未编号章节和已编号章节进行修补以\chapterlinesformat
删除或添加此层:scrheadings
plain.scrheadings
\usepackage{xpatch}
\xpretocmd\chapterlinesformat
{\ifstr{#1}{chapter}
{\ifstr{#2}{}
{% remove the fancytab.odd if the chapter is unnumbered
\RemoveLayersFromPageStyle{scrheadings}{fancytab.odd}%
\RemoveLayersFromPageStyle{plain.scrheadings}{fancytab.odd}%
}
{% add the fancytab.odd if the chapter is numbered
\IfLayerAtPageStyle{scrheadings}{fancytab.odd}{}
{\AddLayersToPageStyle{scrheadings}{fancytab.odd}}%
\IfLayerAtPageStyle{plain.scrheadings}{fancytab.odd}{}
{\AddLayersToPageStyle{plain.scrheadings}{fancytab.odd}}%
}%
}{}%
}{}{\PatchFailed}
注意:如果您以相同的方式设置选项chapterprefix
、appendixprefix
或\chapterlineswithprefixformat`之一。headings=twolinechapter
headings=twolineappendix, you have to patch
例子:
\documentclass{scrbook}
% changed scrpage2 from fancytabs documentation example to the newer scrlayer-scrpage package
\usepackage{scrlayer-scrpage}
\usepackage{fancytabs}
\usepackage{lipsum}
\fancytabsHeight{1.5cm}
%\fancytabsGap{}
%Define the maximum amount of tabs on a page. After \tabcount tabs are displayed, the next tab is displayed on top of the page again.
\fancytabsCount{6}
\fancytabsLeftColor{gray!50}
\fancytabsRightColor{gray!50}
\fancytabsRotate{0}
\fancytabsFloor{0}
\DeclareNewLayer[
background,
oddpage,
contents={\fancytab{\color{white}\thechapter}{\thechapter}}
]{fancytab.odd}
\usepackage{xpatch}
\xpretocmd\chapterlinesformat
{\ifstr{#1}{chapter}
{\ifstr{#2}{}
{% remove the fancytab.odd if the chapter is unnumbered
\RemoveLayersFromPageStyle{scrheadings}{fancytab.odd}%
\RemoveLayersFromPageStyle{plain.scrheadings}{fancytab.odd}%
}
{% add the fancytab.odd if the chapter is numbered
\IfLayerAtPageStyle{scrheadings}{fancytab.odd}{}
{\AddLayersToPageStyle{scrheadings}{fancytab.odd}}%
\IfLayerAtPageStyle{plain.scrheadings}{fancytab.odd}{}
{\AddLayersToPageStyle{plain.scrheadings}{fancytab.odd}}%
}%
}{}%
}{}{\PatchFailed}
\begin{document}
\tableofcontents{}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\addchap{Unnumbered chapter}
\lipsum
\lipsum
\end{document}
运行三次得到:
如果目录是第一章,且是唯一未编号的章节,那么可以在目录完成后添加图层:
\documentclass{scrbook}
% changed scrpage2 from fancytabs documentation example to the newer scrlayer-scrpage package
\usepackage{scrlayer-scrpage}
\usepackage{fancytabs}
\usepackage{lipsum}
\fancytabsHeight{1.5cm}
%\fancytabsGap{}
%Define the maximum amount of tabs on a page. After \tabcount tabs are displayed, the next tab is displayed on top of the page again.
\fancytabsCount{6}
\fancytabsLeftColor{gray!50}
\fancytabsRightColor{gray!50}
\fancytabsRotate{0}
\fancytabsFloor{0}
\DeclareNewLayer[
background,
oddpage,
contents={\fancytab{\color{white}\thechapter}{\thechapter}}
]{fancytab.odd}
\AfterStartingTOC[toc]{%
\cleardoublepage
\AddLayersToPageStyle{scrheadings}{fancytab.odd}%
\AddLayersToPageStyle{plain.scrheadings}{fancytab.odd}%
}
\begin{document}
\tableofcontents{}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\end{document}
当所有设置scrheadings
完成后,您还可以定义一个新的图层页面样式。首先您可以克隆scrheadings
:
\newpairofpagestyles[scrheadings]{fancytabs}{}
然后您可以将图层添加到新的页面样式中:
\AddLayersToPageStyle{fancytabs}{fancytab.odd}
\AddLayersToPageStyle{plain.fancytabs}{fancytab.odd}
例子:
\documentclass{scrbook}
% changed scrpage2 from fancytabs documentation example to the newer scrlayer-scrpage package
\usepackage{scrlayer-scrpage}
\usepackage{fancytabs}
\usepackage{lipsum}
\fancytabsHeight{1.5cm}
%\fancytabsGap{}
%Define the maximum amount of tabs on a page. After \tabcount tabs are displayed, the next tab is displayed on top of the page again.
\fancytabsCount{6}
\fancytabsLeftColor{gray!50}
\fancytabsRightColor{gray!50}
\fancytabsRotate{0}
\fancytabsFloor{0}
\DeclareNewLayer[
background,
oddpage,
contents={\fancytab{\color{white}\thechapter}{\thechapter}}
]{fancytab.odd}
\newpairofpagestyles[scrheadings]{fancytabs}{}
\AddLayersToPageStyle{fancytabs}{fancytab.odd}
\AddLayersToPageStyle{plain.fancytabs}{fancytab.odd}
\begin{document}
\tableofcontents
\cleardoublepage
\pagestyle{fancytabs}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\end{document}
如果您使用这对新的页面样式,那么您可以使用以下方法删除部分页面上的缩略图\renewcommand*\partpagestyle{plain.scrheadings}
:
\documentclass{scrbook}
% changed scrpage2 from fancytabs documentation example to the newer scrlayer-scrpage package
\usepackage{scrlayer-scrpage}
\usepackage{fancytabs}
\usepackage{lipsum}
\fancytabsHeight{1.5cm}
%\fancytabsGap{}
%Define the maximum amount of tabs on a page. After \tabcount tabs are displayed, the next tab is displayed on top of the page again.
\fancytabsCount{6}
\fancytabsLeftColor{gray!50}
\fancytabsRightColor{gray!50}
\fancytabsRotate{0}
\fancytabsFloor{0}
\DeclareNewLayer[
background,
oddpage,
contents={\fancytab{\color{white}\thechapter}{\thechapter}}
]{fancytab.odd}
\newpairofpagestyles[scrheadings]{fancytabs}{}
\AddLayersToPageStyle{fancytabs}{fancytab.odd}
\AddLayersToPageStyle{plain.fancytabs}{fancytab.odd}
\renewcommand\partpagestyle{plain.scrheadings}% <- added
\begin{document}
\tableofcontents
\cleardoublepage
\pagestyle{fancytabs}
\part{A part}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\end{document}