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
\AtBeginEnvironment{theindex}{\addthumbindex[bleed]{.5cm}{thumbindexgray}}
% patch `end{theindex}` to clear the border
\AtEndEnvironment{theindex}{\clearthumbindex}
\newcommand{\addthumbindex}[3][]{
\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.