13

I'm using \printindex for my index and I wonder how to have

  1. bold page numbers
  2. ordering by first character of the indexed word and have dots in between the name and page number like

A
Apple .... 1
Always ... 5

B
Bottle ... 2
Beauty ... 7

lockstep
  • 250,273
tim
  • 1,407

1 Answers1

20

I'm assuming that your index was generated with the help of the makeindex program. This program is automatically called when you compile a LaTeX document with makefiles like latexmk and may also be called by editors like TeXworks or TeXnicCenter. The output generated by makeindex can be configured by using an .ist style file. Details about creating such a file can be found e.g. in section 11.2 of the LaTeX Companion. The following example file would create bold headings for each index letter group and add dots between index keywords and page numbers.

headings_flag 1
heading_prefix "{\\bfseries "
heading_suffix "}\\nopagebreak\n"
delim_0 " \\dotfill "
delim_1 " \\dotfill "
delim_2 " \\dotfill "

To use the file, save it as mystyle.ist and call makeindex with the parameter

-s mystyle.ist

when compiling your LaTeX document. How to exactly add this parameter depends on your compilation method. As a quick workaround: If your main document is called <name>.tex, save the above file as <name>.mst (note the different file type!), copy it to your working directory and compile <name>.tex as usual.

Note that there is a package called idxlayout (disclosure: I'm the package author). This package acts as a complement to .ist files for configuring index layout parameters, e. g. allowing for three-column indexes or for "parent" items and their affiliated subitems being typeset as a single paragraph.

lockstep
  • 250,273
  • 1
    Awesome! Thanks! As I use TexnicCenter, I could define the option "-s stylefile.ist" for my compilation-profile easily! Works great!! – tim May 03 '11 at 09:51
  • 2
    Could you please explain me how to make the font of the main-items bold? Tried it with item_0 "\n \\bf{\\item}" but this makes also the dots, the page number and the subitems bold... – tim May 03 '11 at 10:05
  • This works also with sections, i.e. heading_prefix "{\\section*{", in order to have consistent formatting with bibliographies grouped by initial letters, like here: http://tex.stackexchange.com/questions/150068/how-to-split-the-bibliography-alphabetically – Martin Jan 07 '16 at 14:20
  • I have a similar problem, but I have to use imakeidx as there are two indices in the book I am typesetting. As I don't have to explcitly call makeindex, I am not sure how I can include the style file. I tried adding it as an option alongwith \usepackage{makeindex} in the preamble, but that doesn't seem to work. Knowing tex, I am sure there will be a way this can be done, but I don't know that. Thanks in advance for any help in the matter. – Sasi Sep 22 '20 at 07:28