0

I wanted to generate a thumb index according to this.

Question 1: how can I define custom colors (preferably in hex code) for the boxes? Edit: I solved this by defining custom colors before and inserting the custom descriptors.

Question 2: I would like to have the thumb indices equally distributed over the whole height of the page (and without overlap), relating to the number of chapters. As in: for chapter 1, the thumb index starts at the very top and is one xth of the length of the page (where x equals the number of chapters), for chapter 2, box of the thumb index starts at the end of the box of chapter one, and so on.

Is there any way I can implement these two things into my document?

Any help would be greatly appreciated.

2
  • Welcome to TeX.SE! What you try so far?
    – Zarko
    Sep 18, 2022 at 8:45
  • I solved Question 1 by trial and error with defining costum colors in the preamble. Sep 18, 2022 at 16:53

1 Answer 1

0

Got it!

I included the MWE with some minor changes, but all are commented.

Changes I made are:

  • sans-serif font in white, small, everything centered
  • size of the thumb index is now one xth of the page height (A4 paper)
  • custom colors defined
  • vertical shift of the thumb index box equals the height of the box
  • width is a little smaller (1.5cm)

Hope this helps for anyone who encounters this as well. :-)

\documentclass[a4paper]{report}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{lipsum}
\usepackage{xcolor}

\pagestyle{plain}

% define custom colors in hex code here:
\definecolor{Thumb1}{HTML}{FB8500}
\definecolor{Thumb2}{HTML}{FD9E02}
\definecolor{Thumb3}{HTML}{FFB703}
\definecolor{Thumb4}{HTML}{817425}
\definecolor{Thumb5}{HTML}{425236}
\definecolor{Thumb6}{HTML}{023047}
\definecolor{Thumb7}{HTML}{219EBC}
\definecolor{Thumb8}{HTML}{58B4D1}
\definecolor{Thumb9}{HTML}{8ECAE6}

% background common settings
\SetBgScale{1}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgContents{}

% auxiliary counter
\newcounter{chapshift}
\addtocounter{chapshift}{-1}

% the list of colors to be used (add more if needed)
\newcommand\BoxColor{%
\ifcase\thechapshift Thumb1\or Thumb2\or Thumb3\or Thumb4\or Thumb5\or Thumb6\or Thumb7\or Thumb8\else Thumb9\fi}

% the main command; the mandatory argument sets the color of the vertical box; the value 3.3cm is for A4 document size and 9 chapters, change accordingly (divide document height in cm by total no. of chapters)
\makeatletter
\newcommand\ChapFrame{%
\AddEverypageHook{%
\ifthenelse{\isodd{\thepage}}
{\SetBgContents{%
\begin{tikzpicture}[overlay,remember picture]
\node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1.5cm, % 1.5cm is the width of the box
text height=3.3cm,align=center,anchor=north east] 
at ($ (current page.north east) + (-0cm,-3.3*\thechapshift cm) $) 
{\rotatebox{90}{\parbox[c][1.5cm][c]{3.3cm}{%
\center\textcolor{white}{\textsf{\scriptsize{\MakeUppercase{\textbf{\leftmark}}}}}}}};
\end{tikzpicture}}%
}
{\SetBgContents{%
\begin{tikzpicture}[overlay,remember picture]
\node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1.5cm, % 1.5cm is the width of the box
text height=3.3cm,align=center,anchor=north west] 
at ($ (current page.north west) + (-0cm,-3.3*\thechapshift cm) $) 
{\rotatebox{90}{\parbox[c][1.5cm][c]{3.3cm}{%
\center\textcolor{white}{\textsf{\scriptsize{\MakeUppercase{\textbf{\leftmark}}}}}}}};
\end{tikzpicture}}
}
\bg@material}%
\stepcounter{chapshift}
}
\makeatother

% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}} 

\begin{document}

\chapter[intro]{Introduction}
\ChapFrame
\lipsum[1-7]

\chapter{Results}
\ChapFrame
\lipsum[1-7]

\chapter{Discussion}
\ChapFrame
\lipsum[1-7]

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .