12

I'm making a reference manual using scrbook. I'd like to include a "tab" that shows the current chapter number in a 1.5cm gray rectangle on the outside edge of every page. Within the rectangle would be the current chapter number. This would allow readers to quickly locate the beginning of a particular chapter by looking at the edge of the printed book.

As an added challenge, the chapter tab needs to move down the page as the chapter number increases. For example, in chapter 1, the chapter tab would be located 1cm from the top of the page; for chapter 2, it would be located 2.5cm from the top of the page (1cm white space, plus 1.5cm for the height of the previous chapter tab), and so on.

Is this possible? If so, how can do implement it?

Rabarberski
  • 6,459
Brent
  • 153

3 Answers3

19

Here's a possibility using the background package (change the settings according to your needs). Using \AddLabels the tabs are activated; \RemoveLabels deactivates the tabs:

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

enter image description here

Gonzalo Medina
  • 505,128
  • This is fantastic, and very helpful. Thanks! Quick follow-up question: if I add an index to the document, the chapter tab appears on the index pages as well. Is it possible to suppress the chapter tab in the index? – Brent Jun 19 '13 at 05:08
  • 1
    @Brent sure, it's possible. In some minutes I'll update my answer with this feature added. – Gonzalo Medina Jun 19 '13 at 14:39
  • 1
    @Brent I've updated my answer. The new code has a command to activate the tabs and another one to deactivate them. – Gonzalo Medina Jun 19 '13 at 15:51
  • Although I really like the screenshots you've provided, I get the following error messages for my document: `! Arithmetic overflow. ...xtheight /\totvalue {chapter}\relax

    l.119 \begin{document}

    ? ! Emergency stop. ...xtheight /\totvalue {chapter}\relax

    l.119 \begin{document}`. How can I fix this?

    – Martin Thoma Dec 22 '13 at 15:33
  • @GonzaloMedina this is a very nice solution, but what to do if I add a bibliography at the end of the document, and if I don't want the label of the previous chapter appears? I use in the documentclass option bibliography=totoc for add its entry at the TOC, but the label is the same. – Iraultza Belaustegigoitia Oct 06 '14 at 19:34
  • This is great!! Thanks. But how can I turn the number, so you can read it horizontally. – Brigitte Bruijns Nov 16 '16 at 20:20
  • @BrigitteBruijns: You can use something like \rotatebox{-90}{\hspace{-1ex}\thechapter} instead of \thechapter. – Emiel Jun 16 '18 at 07:35
  • I have about 14 chapters in my thesis and after chapter 8 the grey block just 'falls off' the page, so I do not have a chapter numbering anymore in chapter 9 and so on – Brigitte Bruijns Aug 20 '18 at 14:41
  • --> I could addapt the size of the block – Brigitte Bruijns Aug 21 '18 at 07:57
  • This breaks when using the \appendix command; see this question. – Andrew Dunning Jan 24 '19 at 14:55
5

In April 2002, the web site of the Koma project, Markus Kohm himself presents both commented code for chapter-thumbs, complemented by a pdf as output.

According to him, it should work with every class with \chapter{}-environment and is based on scrpage2. While xcolor allows coloured backgrounds, graphicx provides rotation of the entries to be printed. In difference to the previously presented solution by Gonzalo Medina, the one by Markus Kohm displays the mark only on the odd side (the right one).

1

The following suggestion bases on an example in the appendix of the KOMA-Script book (German):

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

Result:

enter image description here

enter image description here

esdd
  • 85,675