# Omit first thumb index with fancytabs package

In my document I would like to add a thumb index, a small rectangle on the right side. This comes in hand when browsing the printed document. I think it looks neat as well.

Eg:

There are several packages available to use for this goal. I would like to use fancytabs.

I got a MWE set up. However, it turns out that the TOC is considered as an chapter as well and gets a thumb index, #0, as well.

How can I omit the first thumb index?

The manual mentions the \fancytabsFloor command, which I thought was designed for this. But setting this, didn't solve it.

CTAN Package Fancytabs: https://ctan.org/pkg/fancytabs

MWE on Overleaf editor: https://v2.overleaf.com/5747617328trvpfsmswrhc

MWE:

\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

\begin{document}
\tableofcontents{}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\end{document}


You are using package scrlayer-scrpage. Therefore I would declare a new layer for the chapter thumbs:

\DeclareNewLayer[
background,
oddpage,
contents={\fancytab{\color{white}\thechapter}{\thechapter}}
]{fancytab.odd}


Then I would patch \chapterlinesformat to remove or add this layer to scrheadings and plain.scrheadings for unnumbered and numbered chapters, respectively:

\usepackage{xpatch}
\xpretocmd\chapterlinesformat
{\ifstr{#1}{chapter}
{\ifstr{#2}{}
{% remove the fancytab.odd if the chapter is unnumbered
}
{% add the fancytab.odd if the chapter is numbered
}%
}{}%
}{}{\PatchFailed}


Note: If you set one of the option chapterprefix, appendixprefix, headings=twolinechapter or headings=twolineappendix, you have to patch\chapterlineswithprefixformat in the same way.

Example:

\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
}
{% add the fancytab.odd if the chapter is numbered
}%
}{}%
}{}{\PatchFailed}

\begin{document}
\tableofcontents{}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}


Run three times to get:

If the TOC is the first chapter and the only one which is unnumbered, then you can add the layer when the TOC is finished:

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

\begin{document}
\tableofcontents{}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\end{document}


You could also define a new layer pagestyle when all settings for scrheadings are done. First you can clone scrheadings:

\newpairofpagestyles[scrheadings]{fancytabs}{}


Then you can add the layer to the new pagestyles:

\AddLayersToPageStyle{fancytabs}{fancytab.odd}


Example:

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

\begin{document}
\tableofcontents
\cleardoublepage
\pagestyle{fancytabs}
\chapter{A chapter}
\lipsum
\lipsum
\chapter{B chapter}
\lipsum
\lipsum
\chapter{C chapter}
\lipsum
\lipsum
\end{document}


If you use this new pair of pagestyles then you can remove the thumbs on part pages using \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}

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

• wow, this is advanced stuff. I am not familiar with xpatch. Thanks very much for this solution. – JohanFit Sep 7 '18 at 14:36
• @JohanFit I have added a version for a document with the TOC as first chapter and no other unnumbered chapter. Then there is no need to patch a command. – esdd Sep 8 '18 at 9:01
• Unfortunately the second version doesn't apply for me. It's like you said, only if there are numbered chapters after the TOC. When you add a bibliography or glossary list, there will be numbered thumb indexes for those sections as well. Can't get the xpatch working with the theme I am using (hepthesis). Looking into a solution with fancyhdr at the moment. – JohanFit Sep 8 '18 at 17:13
• I have added a third version using a new pair of layer page styles. For the first version: your class sets KOMA-option chapterprefix. So you have to patch \chapterlineswithprefixformat, ie replace \chapterlinesformat by \chapterlineswithprefixformat in the first exampgle. – esdd Sep 8 '18 at 23:23
• If you use the third example with the new layer pagestyles, you only have to redefine \partpagestyle : \renewcommand*\partpagestyle{plain.scrheadings}`. – esdd Oct 3 '18 at 12:04