[Tex/LaTex] How to set a letter to the margin of the page and position it vertically according to alphabetical order


I would like to place a letter (that indicates which letter in the dictionary is shown) on the outer side of the book, set it for example in a darker box and position that letter vertically. Users of the dictionary can later easily access a searched headword by using the letter division on the side.

Minimum example:

\usepackage[top=1.5cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
\usepackage[utf8x, utf8]{inputenc}
\newcommand\entry[3][]{\hangpara{2em}{1}{\fontfamily{phv} selectfont{\textbf{{#2}}}}\ 

How can I place thumb indexes from \dictchar values now to the right odd and left even margin?

Best Answer

I guess what you want are chapter thumbs or a thumb index. Here’s a nearly automatic solution using TikZ:



% load TikZ to draw the boxes

% use scrpage2 or whatever you want to add
% the boxes to the header to make them appear
% on every page

% new counter to hold the current number of the 
% letter to determine the vertical position
% newcounter to set the number of thumbs fitting vertical
% and setting the height of a boxes
% some margin settings
% calculate the box height by dividing the page height
% box width
% style the boxes
        minimum height=\thumbheight,
        text width=\thumbwidth,
        outer sep=0pt,
        inner xsep=1.5em,
% create two new commands to make the thumbs
% that makes it easy to use them im different header elements,
% like in the plain and normal page style etc.
     % see pgfmanual.pdf for more information about this part
     \begin{tikzpicture}[remember picture, overlay]
         \node [thumb,align=left,anchor=north west,] at ($%
             (current page.north west)-%
         $) {#1};
     \begin{tikzpicture}[remember picture, overlay]
         \node [thumb,align=right,anchor=north east,] at ($%
             (current page.north east)-%
         $) {#1};
% create a new command to set a new lettergroup
    % but I recommend to start a new page
    % set a title (optional)
    {\Huge\bfseries\sffamily #1}\par\bigskip
    % check if we reached the last vertical position and reset it
    % check if we reached the last vertical position and reset it
    % use one head or foot element to put in the box
    % it doesn't matter which you use since the box
    % is positioned on the page absolutely

% for some blindtext


% usage: \lettergroup{<letter>}
% e.g.
% your text








I made an update so it is now possible to set how many letter thumbs should fit in the margin before the next letter group starts from the to again. Thats better for a high number of group where the box height will be very small otherwise. I renamed lettersum by letterdiv so the name matches the function.

The counter letterdiv is used to set the number of boxes fitting in the page height. I set it to 4 in my example to show how it works. As you can see the fifth letter E is printed at the first position form to again.