12

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.

First issue

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.

enter image description here

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}
  • Maybe I misunderstand the purpose, but shouldn't thumb indexes only be on verso pages? – Harald Jan 23 '15 at 10:02
  • It's possible that thumb index usually means a tab on one side of the page, but in this case the thumb index is put on each side - that way the colour on the edge of the dictionary will be visible and can help user to find the letter more quickly. – chejnik Jan 23 '15 at 11:40
  • Do you want no thumb index on pages where no headers appear, or do you want the current thumb index to carry across those pages? – Steven B. Segletes Jan 26 '15 at 13:26
  • I want to achieve that thumb index(es) correspond(s) to the first letter of the headwords that appear on the page. For example in the first picture there should be thumbindex E, Ë, F, on the second picture there should be only letter F. – chejnik Jan 26 '15 at 14:04
7
+50

EDITED to handle diacritic tabs. REEDITED to correct tab colors when multiple tabs appear on a single page.

Here's the fix using your existing fancy interface, rather than the home-brew concoction of my other answer. Let me show the changes:

Initializations:

\def\thumbnew{}
\def\thumbold{}

If there are no new thumbs on a page, use the last of the old thumbs

\usepackage{everypage}
\AddEverypageHook{\if\relax\thumbnew\relax\xdef\thumbnew{\thumbold}\fi}

Here are changes to \lettergroup. Here, in a manner inverse to my original approach, I had to create a \Let1=a, \Let2=\"a, \Let3=b series of macros (this will now allow umlauted arguments). Then, I create \thumbnew as an enumerated list of the thumb slots. On page 1, it is 2,1,, on page 2, 5,4,3,, etc. Rather than calling on \fancyhead with a single thumb, which overwrites any prior thumb on the same page, I instead pass it the argument \expandafter\ethumbs\thumbnew\relax\relax\relax to parse \thumbnew and insert all of those thumbs into the \fancyhead at once.

 \newcommand{\lettergroup}[1]{%
% step the counter of the letters
  \refstepcounter{letternum}%
  \expandafter\gdef\csname Let\theletternum\endcsname{#1}%
  \xdef\thumbnew{\theletternum,\thumbnew}%
  \fancyhead[LO]{\fontfamily{phv}\selectfont{\textbf{\rightmark}}%
    \expandafter\ethumbs\thumbnew\relax\relax\relax}%
  \fancyhead[RE]{\fontfamily{phv}\selectfont{\textbf{\leftmark}}%
    \expandafter\othumbs\thumbnew\relax\relax\relax}%
 }

The thumbs parsers are these recursive routines. They parse a slot at a time and call on the appropriate thumb. But they also reset \thumbnew to {} and set \thumbold, upon exit, to the first (i.e., the most recent) argument in the thumb list.

\def\ethumbs#1,#2\relax{\if\relax#1\relax\else\eventhumb{#1}\fi%
                       \if\relax#2\relax\else\ethumbs#2\relax\fi%
                       \gdef\thumbnew{}%
                       \gdef\thumbold{#1,}%
}
\def\othumbs#1,#2\relax{\if\relax#1\relax\else\oddthumb{#1}\fi%
                      \if\relax#2\relax\else\othumbs#2\relax\fi%
                       \gdef\thumbold{#1,}%
                       \gdef\thumbnew{}%
}

Finally, the thumbs themselves are created. Unlike my original approach, the argument to the macro is a slot number (not the tab letter), which is used to determine the vertical placement of the tab with \thumbtopmargin+#1*\thumbheight. The associated tab letter is reconstituted with \csname Let#1\endcsname (i.e., \Let1, \Let2, etc., which contain the letter associated with the slot).

 \newcommand{\oddthumb}[1]{%
    % see pgfmanual.pdf for more information about this part
    \begin{tikzpicture}[remember picture, overlay]
        \node [thumb,fill=\BoxColor{#1}, text centered,anchor=north east,] at ($%
            (current page.north east)-%
            (0,\thumbtopmargin+#1*\thumbheight)%
        $) {\csname Let#1\endcsname};
   \end{tikzpicture}
  }
 \newcommand{\eventhumb}[1]{%
    % see pgfmanual.pdf for more information about this part
    \begin{tikzpicture}[remember picture, overlay]
        \node [thumb,fill=\BoxColor{#1}, text centered,anchor=north west,] at ($%
            (current page.north west)-%
            (0,\thumbtopmargin+#1*\thumbheight)%
        $) {\csname Let#1\endcsname};
   \end{tikzpicture}
   }

In these macros, \Boxcolor was redefined to take an argument (the slot number). This requires a redefinition of \Boxcolor as

\newcommand\BoxColor[1]{%
\ifcase#1 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}

or, if the OP prefers the colors from my other solution,

\def\BoxColor#1{red!\the\numexpr103-#1-#1-#1\relax!blue}

This latter form will work with 34 or fewer tabs. If there are more, then only two, not three subtractions of #1 are permitted.

Here is the MWE:

\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[1]{%
\ifcase#1 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}

% ALTERNATE COLOR SCHEME
%\def\BoxColor#1{red!\the\numexpr103-#1-#1-#1\relax!blue}

%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,
 }
 }
\def\thumbnew{}
\def\thumbold{}
\usepackage{everypage}
\AddEverypageHook{\if\relax\thumbnew\relax\xdef\thumbnew{\thumbold}\fi}

\def\ethumbs#1,#2\relax{\if\relax#1\relax\else\eventhumb{#1}\fi%
                       \if\relax#2\relax\else\ethumbs#2\relax\fi%
                       \gdef\thumbnew{}%
                       \gdef\thumbold{#1,}%
}
\def\othumbs#1,#2\relax{\if\relax#1\relax\else\oddthumb{#1}\fi%
                      \if\relax#2\relax\else\othumbs#2\relax\fi%
                       \gdef\thumbold{#1,}%
                       \gdef\thumbnew{}%
}

 \newcommand{\oddthumb}[1]{%
    % see pgfmanual.pdf for more information about this part
    \begin{tikzpicture}[remember picture, overlay]
        \node [thumb,fill=\BoxColor{#1}, text centered,anchor=north east,] at ($%
            (current page.north east)-%
            (0,\thumbtopmargin+#1*\thumbheight)%
        $) {\csname Let#1\endcsname};
   \end{tikzpicture}
  }
 \newcommand{\eventhumb}[1]{%
    % see pgfmanual.pdf for more information about this part
    \begin{tikzpicture}[remember picture, overlay]
        \node [thumb,fill=\BoxColor{#1}, text centered,anchor=north west,] at ($%
            (current page.north west)-%
            (0,\thumbtopmargin+#1*\thumbheight)%
        $) {\csname Let#1\endcsname};
   \end{tikzpicture}
   }
   % create a new command to set a new lettergroup with thumb indexes
 \newcommand{\lettergroup}[1]{%
% step the counter of the letters
  \refstepcounter{letternum}%
  \expandafter\gdef\csname Let\theletternum\endcsname{#1}%
  \xdef\thumbnew{\theletternum,\thumbnew}%
  \fancyhead[LO]{\fontfamily{phv}\selectfont{\textbf{\rightmark}}%
    \expandafter\ethumbs\thumbnew\relax\relax\relax}%
  \fancyhead[RE]{\fontfamily{phv}\selectfont{\textbf{\leftmark}}%
    \expandafter\othumbs\thumbnew\relax\relax\relax}%
 }


 \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-4]

 \lettergroup{\"a}
 \dictchar{\"A~\"a}
 \lipsum[6-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-23]

 \lettergroup{g}
 \dictchar{G~g}
 \lipsum[1-23]
 \lettergroup{h}
 \lettergroup{i}
 \lettergroup{j}
 \lettergroup{k}
 \lettergroup{l}
 \lettergroup{m}
 \lettergroup{n}
 \lettergroup{o}
 \lettergroup{\"o}
 \lettergroup{p}
 \lettergroup{q}
 \lettergroup{r}
 \lettergroup{s}
 \lettergroup{s}
 \lettergroup{t}
 \lettergroup{u}
 \lettergroup{v}
 \lettergroup{w}
 \lettergroup{x}
 \lettergroup{y}
 \lettergroup{z}
\lipsum[1-15]

 \end{document}

Here is one page, showing the seamless use of diacritics on the tabs.

enter image description here

  • Is there a way how to include the accented letters as thumb indexes (actually letters of Icelandic alphabet)? I have probably made mistake while not including \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} in my ME. – chejnik Jan 27 '15 at 6:51
  • The only way I can think is to dispense with the logic of \expandafter\gdef\csname Let#1\endcsname{\the\numexpr `#1 - `` \relax} (which is then used as \thumbtopmargin+\csname Let#1\endcsname*\thumbheight), and instead pass the "tab number" as a separate argument to \lettergroup. If I get a chance to look into it, I might. – Steven B. Segletes Jan 27 '15 at 11:24
  • 1
    @chejnik Please see revision. Diacritics are now enabled. – Steven B. Segletes Jan 27 '15 at 12:16
  • 1
    @chejnik Colors are now corrected with multi-tab pages. – Steven B. Segletes Jan 27 '15 at 12:45
  • 1
    That is informative answer with an explanation of code and even new interesting idea (colour algorithm). Many thanks :) – chejnik Jan 27 '15 at 13:11
7

I don't use fancy, but rather a home-brewed concoction. I EDITED to excise the unneeded fancy and tikz calls. Also, I did not employ your colors, but used an algorithm for varying the colors. Finally, this only works for ascii \lettergroups at present, so no umlauted e's will get a tab.

I use everypage as the vehicle, employing logic similar to my answer at Coloured swatch per chapter. In this case, I use an \AtThisPageHook to introduce new tabs to the document, and an \AtEveryPageHook to reiterate the last known tab (to tab pages where no new tabs are introduced). I also use an \AtEveryPageHook to flip-flop the tabs on even/odd pages.

Here are some of the code highlights. \lettergroup has been changed as follows: \CurrentLetter contains the most recent tab name, which is used by the subsequent one-time invocation of \AddEverypageHook (invoked when \CLet=0). \Clet contains the most recent tab number (a=0, b=1, ...). The call to \atxy invokes a tab for the current page.

  \newcommand{\lettergroup}[1]{%
  \gdef\CurrentLetter{#1}%
  \gdef\CLet{\the\numexpr `#1 - `a\relax}%
  \atxy{#1}%
  \ifnum\CLet=0\AddEverypageHook{%
    \smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+\localX\relax}%
    \raisebox{%
      \dimexpr\PageTopMargin+\voffset-\Yloc-\CLet\dYloc\relax}%
      {\expandafter\mytab\expandafter{\CurrentLetter}}}}%
  \fi
 }

The macro \atxy, as mentioned, adds a tab for the current page It uses \csname Let#1\endcsname\dYloc (which expands to \Leta, \Letb, etc.) to calculate the number of \dYloc increments to vertically translate the tab downward.

\newcommand\atxy[1]{%
  \expandafter\def\csname Let#1\endcsname{\the\numexpr `#1 - `a\relax}%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+\localX\relax}%
  \raisebox{%
    \dimexpr\PageTopMargin+\voffset-\Yloc-\csname Let#1\endcsname\dYloc\relax}%
    {\mytab{#1}}}}%
}

In this defininition of \atxy, you will note that the only way I was able to get multiple tabs on a page was to create a unique macro during each invocation (#1 is the letter being tabbed)

\expandafter\def\csname Let#1\endcsname{\the\numexpr `#1 - `a\relax}%

which produces \Leta=0, \Letb=1, etc., and use it as a multiplier on the y shift distance. I came to this approach after giving up on, as an alternative, defining \Let as a rolling index. With that approach, it invariably used the final value of \Let on a page, rather than a rolling value as desired.

The following everypage logic

\AddEverypageHook{%
  \ifdim\localX=\ThisX\gdef\localX{\AltX}\else\gdef\localX{\ThisX}\fi%
}

is what switches the tab from left to right and vice versa with each page.

Finally,

\def\mytab#1{\stackon[-11pt]{%
  \textcolor{red!\the\numexpr391-`#1-`#1-`#1\relax!blue}{%
    \rule{\tabwidth}{\tabheight}}}{\textcolor{white}{\sffamily\bfseries#1}}}

is what defines the tab itself.

User parameters include

\def\ThisX{0in}% This page x-location of tab
\def\AltX{6.11in}% Alternate page x-location of tab
\Yloc=2.15cm\relax% Y location of first tab
\dYloc=16.6pt\relax% downward shift of successive tabs
\def\tabwidth{19.5pt}% tab width
\def\tabheight{\the\dimexpr\the\dYloc+.2pt\relax}% tab height

Here is my MWE

\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{graphicx}
\usepackage{xcolor}
% for some blindtext
\usepackage{lipsum}

   % create a new command to set a new lettergroup with thumb indexes
  \newcommand{\lettergroup}[1]{%
  \gdef\CurrentLetter{#1}%
  \gdef\CLet{\the\numexpr `#1 - `a\relax}%
  \atxy{#1}%
  \ifnum\CLet=0\AddEverypageHook{%
    \smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+\localX\relax}%
    \raisebox{%
      \dimexpr\PageTopMargin+\voffset-\Yloc-\CLet\dYloc\relax}%
      {\expandafter\mytab\expandafter{\CurrentLetter}}}}%
  \fi
 }

 \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

\usepackage{everypage,stackengine}

% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newlength\Yloc
\newlength\dYloc
\def\localX{-1in}
\def\ThisX{0in}
\def\AltX{6.11in}
\Yloc=2.15cm\relax
\dYloc=16.6pt\relax
\def\tabwidth{19.5pt}
\def\tabheight{\the\dimexpr\the\dYloc+.2pt\relax}
% SYNTAX \atxy{This page X}{Alt page X}{y}{content}
\newcommand\atxy[1]{%
  \expandafter\def\csname Let#1\endcsname{\the\numexpr `#1 - `a\relax}%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+\localX\relax}%
  \raisebox{%
    \dimexpr\PageTopMargin+\voffset-\Yloc-\csname Let#1\endcsname\dYloc\relax}%
    {\mytab{#1}}}}%
}
\AddEverypageHook{%
  \ifdim\localX=\ThisX\gdef\localX{\AltX}\else\gdef\localX{\ThisX}\fi%
}
\def\mytab#1{\stackon[-11pt]{%
  \textcolor{red!\the\numexpr391-`#1-`#1-`#1\relax!blue}{%
    \rule{\tabwidth}{\tabheight}}}{\textcolor{white}{\sffamily\bfseries#1}}}
 \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-15]

 \lettergroup{g}
 \lettergroup{h}
 \lettergroup{i}
 \lettergroup{j}
 \lettergroup{k}
 \lettergroup{l}
 \lettergroup{m}
 \lettergroup{n}
 \lettergroup{o}
 \lettergroup{p}
 \lettergroup{q}
 \lettergroup{r}
 \lettergroup{s}
 \lettergroup{s}
 \lettergroup{t}
 \lettergroup{u}
 \lettergroup{v}
 \lettergroup{w}
 \lettergroup{x}
 \lettergroup{y}
 \lettergroup{z}
\lipsum[1-15]

 \end{document}

Here is a page with multiple tabs

enter image description here

here is a page with no new tabs

enter image description here

and here is the color range of tabs (just shown by way of artificial invocation)

enter image description here

  • The algorithm for varying the colors is beautiful !! – chejnik Jan 27 '15 at 9:32
  • 1
    @chejnik Thank you. As a totally unrelated side note, I see from your profile that my Mom was born not too from your location, about 100 yards from the south side of the bridge at Wloclawek. Too bad I don't know a bit of Polish, but only German. – Steven B. Segletes Jan 27 '15 at 11:21
  • That is very nice to hear :). It's a beautiful country. – chejnik Jan 27 '15 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.