# Custom border for glossary and index pages

I'm preparing a technical book in Latex using KOMA script srcbook class and I would like to add a gray border ONLY to glossary and index pages. The idea is to make them easy to find when the book is closed, like in the sample below:

I have seen similar solutions using fancyhdr or tikz but (1) I don't know if they can be applied directly without screwing KOMA, and (2) I've found no way to limit the border only to index/glossary pages and I'm sure there must be an obvious way to do both things.

UPDATE: I found a solution (see below) using the eso-pic and ifthen packages to draw the border and the etoolbox to patch the theindex environment and control where it appears.

• this looks like a request for "thumb indexex". see Adding chapter marker to far right edge of page. i don't know whether there might be incompatibility with the koma script classes. Jun 27, 2013 at 18:44
• This is not exactly what I had in mind but with some tinkering it might produce what I need. Thanks! Jun 27, 2013 at 18:55

You can use the package background in combination with TikZ and the defined node current page:

\documentclass{scrbook}
\usepackage[]{background}
\backgroundsetup{contents={}}
\usepackage{lipsum}
\usepackage{imakeidx}

\makeindex
\begin{document}
\index{a}\lipsum[1-10]

\tikz[remember picture,overlay]\draw[line width=1cm](current page.north east) rectangle (current page.south east);%
}
\printindex
\end{document}

• Curiously enough, the \backgroundsetup{contents={}} line gives the following error: ! Undefined control sequence. Could it be a problem with Latex's version? Jun 27, 2013 at 19:29
• Changing \backgroundsetup{contents={}} to \SetBgContents{} mostly works with my package version. The border is drawn correctly but for some reason begins the page BEFORE the actual index begins. Jun 27, 2013 at 20:22
• @AlbertoMiranda: I am using TeX Live 2013. Jun 27, 2013 at 20:38
• It seems that with my version there are some incompatibilities between background or tikz (don't know which one) and KOMA. I found a solution that works in my system without using either, but your answer helped me find related solutions. Thanks! Jun 28, 2013 at 9:53
• @AlbertoMiranda: Instead of trying a hack you should update your system. Jun 28, 2013 at 17:22

I'm answering my own question in hope that someone will find it useful later on.

My solution is inspired and based on this answer since using Tikz shows some weird behavior with the scrbook class (at least in my system). I've created two new commands \addthumbindex and \clearthumbindex that can be used to enable and disable the thumbindex respectively. The first command receives the thumbindex's color and width as mandatory arguments, and you can also specify an optional bleed argument if you need to print in A4 but want it cropped to B5 (the MWE below shows an example).

This solution is not perfect though: as you can see in the following picture, I haven't been able to remove the border in the page BEFORE the actual index begins, so I'm still searching for a solution (whether it's an improvement on mine or a different method altogether). EDIT: FIXED.

\documentclass[b5paper]{scrbook}
\usepackage[a4,cam,center]{crop} % to show cropping marks (if needed)
\usepackage{xcolor}              % to have colors
\usepackage{eso-pic}             % put things into background
\usepackage{ifthen}              % support for conditionals
\usepackage{imakeidx}            % to create the index

\usepackage{lipsum}              % for sample text

\definecolor{thumbindexgray}{RGB}{102,102,102}

% patch begin{theindex} to add the border

% patch end{theindex} to clear the border
\AtEndEnvironment{theindex}{\clearthumbindex}

\newlength{\thumbindexwidth}
\setlength{\thumbindexwidth}{#2}

\ifthenelse{\equal{#1}{bleed}}{
%\clearpage (not needed if we patch 'theindex' environment)
\AddToShipoutPicture{% from package eso-pic: put something to the background
\ifthenelse{\isodd{\thepage}}{
% odd page: right bar
\AtPageLowerLeft{% start the bar at the bottom right of the page
\put(\LenToUnit{\dimexpr\paperwidth+\thumbindexwidth-2\thumbindexwidth},
\LenToUnit{\dimexpr-\thumbindexwidth}){% move it to the top right
\color{#3}\rule{2\thumbindexwidth}{\LenToUnit{\dimexpr\paperheight+2\thumbindexwidth}}%
}%
}%
}%
{%
% even page: left bar
\AtPageLowerLeft{% start the bar at the left bottom of the page
\put(\LenToUnit{\dimexpr\thumbindexwidth-2\thumbindexwidth},
\LenToUnit{\dimexpr-\thumbindexwidth}){% move it to the top right
\color{#3}\rule{2\thumbindexwidth}{\LenToUnit{\dimexpr\paperheight+2\thumbindexwidth}}%
}%
%\color{#3}\rule{\thumbindexwidth}{\LenToUnit\paperheight}%
}%
}%
}
}
{
%\clearpage (not needed if we patch 'theindex' environment)
\AddToShipoutPicture{% from package eso-pic: put something to the background
\ifthenelse{\isodd{\thepage}}{
% odd page: right bar
\AtPageLowerLeft{% start the bar at the bottom right of the page
\put(\LenToUnit{\dimexpr\paperwidth-\thumbindexwidth},0){% move it to the top right
\color{#3}\rule{\thumbindexwidth}{\LenToUnit\paperheight}%
}%
}%
}%
{%
% even page: left bar
\AtPageLowerLeft{% start the bar at the left bottom of the page
\color{#3}\rule{\thumbindexwidth}{\LenToUnit\paperheight}%
}%
}%
}
}
}

\newcommand{\clearthumbindex}{
\clearpage
\ClearShipoutPicture
}

\makeindex

\begin{document}

\input{fake_index.tex} % just a collection of \index{XXX}\lipsum[1-10]

% \addthumbindex[bleed]{.5cm}{thumbindexgray} % (not needed if patching 'theindex')
\printindex
% \clearthumbindex{}  % (not needed if patching 'theindex')

\end{document}


EDIT: I found a solution by patching the theindex environment generated by makeindex using the etoolbox package. For future reference, the code works both in pdflatex and in xelatex and I assume that something similar will work with glossaries or acronym lists. I've added my changes to the code above and a picture of the final result below.