The original question with accepted answers shows how to set a letter to the margin of the page and position it vertically according to alphabetical order.
There appears two issues that I need to correct. Both issues are illustrated by pictures.
First issue
The first issue appears when there are on one page headwords beginning with more than one letter. In this case more thumb indexes need to be placed on that page.
Second issue
The second issue appears when the title letters starts directly (more or less) at the top of the page as illustrates the second picture (title letters Gg starts on page 175 but the thumb index with G begins on page 174). In this case and generally the letter(s) of thumb index has to correspond with the first letter of all headwords on the page.
ME follows:
\documentclass[8pt,c5paper,twocolumn]{extbook}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage[paper=c5paper, top=1.5cm, headsep=0.4cm, bottom=1.5cm, left=1cm, right=1cm]{geometry}
\usepackage{fancyhdr}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{graphicx}
\usepackage{color}
% for some blindtext
\usepackage{lipsum}
% COLORS
\definecolor{darkgreen}{rgb}{0.4, 0.01, 0.24}
\definecolor{color1}{RGB}{182, 86, 0}
\definecolor{color2}{RGB}{143, 9, 6}
\definecolor{color3}{RGB}{3, 23, 118}
\definecolor{color4}{RGB}{0, 82, 168}
\definecolor{color5}{RGB}{0, 85, 142}
\definecolor{color6}{RGB}{0, 115, 162}
\definecolor{color7}{RGB}{34, 146, 186}
\definecolor{color8}{RGB}{40, 159, 153}
\definecolor{color9}{RGB}{0, 125, 111}
\definecolor{color10}{RGB}{4, 107, 60}
\definecolor{color11}{RGB}{71, 134, 81}
\definecolor{color12}{RGB}{109, 134, 42}
\definecolor{color13}{RGB}{205, 194, 18}
\definecolor{color14}{RGB}{204, 162, 24}
% Thumb indexes' colors
\newcommand\BoxColor{%
\ifcase\theletternum darkgreen!30\or color1\or color2\or color3\or color4\or color5\or color6\or color7\or color8\or color9\or color10%
\or color11\or color12\or color13\or color14\or color1\or color2\or color3\or color4\or color5\or color6\or color7\or color8\or color9%
\or color10\or color11\or color12\or color13\or color14\or color1\or color2\or color3\or color4\or color5\or color6\else color7\or color8\or color9\or color10\or color11\or color12\fi}
%FANCY PAGE STYLES
\pagestyle{fancy}
% THUMB INDEXES
% new counter to hold the current number of the letter to determine the vertical position
\newcounter{letternum}
% newcounter for the sum of all letters to get the right height of a box
\newcounter{lettersum}
\setcounter{lettersum}{33}
% some margin settings
\newlength{\thumbtopmargin}
\setlength{\thumbtopmargin}{1cm}
\newlength{\thumbbottommargin}
\setlength{\thumbbottommargin}{2.5cm}
% calculate the box height by dividing the page height
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}{%
(\paperheight-\thumbtopmargin-\thumbbottommargin)%
/%
\value{lettersum}
}
% box width
\newlength{\thumbwidth}
\setlength{\thumbwidth}{0.5cm}
% style the boxes
\tikzset{
thumb/.style={
text=white,
minimum height=\thumbheight,
text width=\thumbwidth,
outer sep=0pt,
font=\sffamily\bfseries,
}
}
\newcommand{\oddthumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
\node [thumb,fill=\BoxColor, text centered,anchor=north east,] at ($%
(current page.north east)-%
(0,\thumbtopmargin+\value{letternum}*\thumbheight)%
$) {#1};
\end{tikzpicture}
}
\newcommand{\eventhumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
\node [thumb,fill=\BoxColor, text centered,anchor=north west,] at ($%
(current page.north west)-%
(0,\thumbtopmargin+\value{letternum}*\thumbheight)%
$) {#1};
\end{tikzpicture}
}
% create a new command to set a new lettergroup with thumb indexes
\newcommand{\lettergroup}[1]{%
%\setcounter{page}{1}
\fancyhead[LO]{\fontfamily{phv}\selectfont{\textbf{\rightmark}}\eventhumb{#1}}%
\fancyhead[RE]{\fontfamily{phv}\selectfont{\textbf{\leftmark}}\oddthumb{#1}}%
% step the counter of the letters
\stepcounter{letternum}%
}
\newcommand*{\dictchar}[1]{
\centerline{\parbox[c][3cm][c]{3cm}{%
\centering
\fontsize{24}{24}
\selectfont
{#1}}}
}
% DICTIONARY PAGE STYLE
\fancypagestyle{dictstyle}{%
\renewcommand{\headrulewidth}{0.4pt}
\fancyhf{}
\fancyhead[LE,LO]{{\fontfamily{phv}\selectfont{\textbf{\rightmark}}}}
\fancyhead[CO,CE]{\thepage}%the page numbers will be printed when the dictionary is ready
\fancyhead[RE,RO]{{\fontfamily{phv}\selectfont{\textbf{\leftmark}}}}}
% middle rule
\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0.01pt}
\newcommand{\HRule}{\rule{\linewidth}{0.1mm}} % rule line
\begin{document}
\twocolumn
\pagestyle{dictstyle}
\lettergroup{a}
\dictchar{A~a}
\lipsum[1-10]
\lettergroup{b}
\dictchar{B~b}
\lipsum[1]
\lettergroup{c}
\dictchar{C~c}
\lipsum[1]
\lettergroup{d}
\dictchar{D~d}
\lipsum[1-5]
\lettergroup{e}
\dictchar{E~e}
\lipsum[1-10]
\lettergroup{f}
\dictchar{F~f}
\lipsum[1-3]
\end{document}