10

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.

1

1 Answer 1

19

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. :)

5
  • 1
    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? Jul 30, 2012 at 15:44
  • @Brent.Longborough: The package imakeidx has this functionality. Jul 30, 2012 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. :) Jul 30, 2012 at 16:18
  • This works also with sections, i.e. heading_prefix "{\\section*{", in order to have consistent formatting with bibliographies grouped by initial letters, like here: tex.stackexchange.com/questions/150068/…
    – Martin
    Jan 7, 2016 at 14:18
  • 1
    I'm using overleaf online, How can I adapt it to the remote version ?
    – Emna Ayadi
    Nov 29, 2020 at 0:50

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