2

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: enter image description here

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

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

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

Run three times to get:

enter image description here


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

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}
\AddLayersToPageStyle{plain.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}

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

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}

\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}
  • wow, this is advanced stuff. I am not familiar with xpatch. Thanks very much for this solution. – JohanFit Sep 7 '18 at 14:36
  • 1
    @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
  • 1
    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
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.