Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
package makeidx: print first letter for each group of keys

I'm trying to adapt the index of my contribution such that each group of words (starting with the same letter) has the starting letter displayed as bold an on top of the group.

Note that I tried to find an answer, but the related questions and answers are rather confusing. I use \documentclass[a4paper,12pt]{book} and \usepackage{makeidx} \makeindex.

share|improve this question

marked as duplicate by Torbjørn T., Paulo Cereda, Marco Daniel, percusse, lockstep Jul 30 '12 at 16:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer

up vote 13 down vote accepted

We need to create an .iststyle file and tell makeindex to use it. My style file is as follows:

headings_flag 1
heading_prefix "{\\textbf{"
heading_suffix "}}\\nopagebreak\n"

The first line tells makeindex to display a heading for each group (1 stands for true). The last two lines will format the heading the way you want (I used textbf to make the heading bold).

Now, with myheader.ist, we simply call

makeindex -s myheader.ist myfile.idx

Consider this example:

% arara: pdflatex
% arara: makeindex: { style: myheader.ist }
% arara: pdflatex
\documentclass[a4paper,12pt]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{makeidx}

\makeindex

\begin{document}

Some text.\index{Apple}\index{Apricot}\index{Avocado}\index{Banana}
\index{Bilberry}\index{Blackberry}\index{Blackcurrant}\index{Blueberry}
\index{Currant}\index{Cherry}\index{Cherimoya}\index{Clementine}
\index{Date}\index{Damson}\index{Dragonfruit}\index{Durian}
\index{Eggplant}\index{Elderberry}\index{Feijoa}\index{Gooseberry}
\index{Grape}\index{Grapefruit}\index{Guava}\index{Huckleberry}
\index{Jackfruit}\index{Jambul}\index{Kiwi fruit}\index{Kumquat}
\index{Legume}\index{Lemon}\index{Lime}\index{Lychee}\index{Mandarine}
\index{Mango}\index{Melon}\index{Nectarine}\index{Orange}\index{Peach}
\index{Pear}\index{Pitaya}\index{Physalis}\index{Plum}\index{Pineapple}
\index{Pomegranate}\index{Purple Mangosteen}\index{Raisin}\index{Raspberry}
\index{Rambutan}\index{Redcurrant}\index{Salal berry}\index{Satsuma}
\index{Star fruit}\index{Strawberry}\index{Tangerine}\index{Tomato}
\index{Ugli fruit}\index{Watermelon}\index{Ziziphus mauritiana}

\printindex

\end{document}

Running the following commands:

pdflatex myfile.tex
makeindex -s myheader.ist myfile.idx
pdflatex myfile.tex

We will obtain this output:

My index

Hope it helps. :)

share|improve this answer
    
I thought that if you use the makeidx package, it runs makeindex internally for you, so you don't need a separate run. Am I mistaken? –  Brent.Longborough Jul 30 '12 at 15:44
    
@Brent.Longborough: The package imakeidx has this functionality. –  Marco Daniel Jul 30 '12 at 16:07
    
@Brent: makeidx provides a couple of extra commands to the default indexing mechanism, but that's all. As Marco mentioned, imakeidx has this feature. :) –  Paulo Cereda Jul 30 '12 at 16:18
add comment

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