Learn How to Create an Index Page in LaTeX


The index in a manuscript helps the reader to find contents in any document. It should be straightforward as much possible. Many authors index words, listing all the pages on which those index words appear. A good writer indexes contextual ideas, facts, features, and so on.



Illustration below illustrates a comparative view of index entries from a “word index” and a “concept index”. Suppose using each of them to find out the topic – testing procedure of VPN connections (Page 598 describes the process) with the word index, a reader has to look seven pages prior to reaching the desired one. On the other hand, with the concept index, he/she can jump to the desired page.

Facts about creating index entries

Prior to generating a list of indexes, the writer should be aware of the following facts:

  • The writer should make a plan of what concepts should b e displayed in the index.
  • Try to figure out the type of the readers and what is their interests about the concepts of an index.
  • Then, try to sketch a blueprint of what types of words generally the readers might need to looking for each concept.
  • Many times the writers were tempted to just list the index words as the way they wrote the document. It is strictly advised to avoid this procedure for creating a good index.
  • One of the professional technique is to start recording index entries according to the alphabetical order for all of the identical words those appear in the manuscript.
  • A computer can’t create an index of a document automatically, though it could help the procedure. It’s the duty of the authors to decide whether the keywords are specific enough to their topics to app ear in the index, or not. If yes, they need to decide where the readers would b e redirected in the index.
  • The computer can notice and count each occurrence of index entries in an efficient technique.
  • In LaTeX, simply adding the command \index (see details in following sections) on the position of the document for what you want to index.

How to Make an Index in LaTeX

1. Use of Keyword Index

LaTeX can not generate an index with keywords automatically. However, it can prepare input data for a program, which generates an index format *.idx form. LaTeX can use this file on later during runtime.

The environment {theindex} in LaTeX is shown as below:

\begin{theindex}
  index_entries
\end{theindex}

It shifts the page environment into a two-column page format with a running Index for the document. Note that, the heading “Index” is printed out on the first page of the index. In a book and report manuscript, the size of this title of the index is the same as “Heading of Chapter”; and in an article, this size is the same as the section heading of the document. To generate the individual entries, you have use the following commands:

LaTeX ExpressionPurpose
\itemFor Keyword Index Entry
\subitemFor Sub Keyword Index Entry
\subsubitemFor Nested Keyword Index Entry
\indexspaceLeaves an Empty Line between Index Entries

If a text in the index entry is too long to accommodate in one line, the program automatically breaks it down on the next immediate line with a deeper indentation than others lines.

% Sample index entry LaTeX code:
\begin{theindex}
 \item Accelerated Graphics Port Cards
  \subitem installing, 43-44
  \subitem upgrading form, 15
\indexspace
 \item Adapters
  \subitem Bluetooth, 113
  \subitem Power Cable, 29
   \subsubitem power connectors, 23
   \subsubitem SATA drives, 39
  \subitem ports, 220
\indexspace
 \item covers, ESD, 50
\indexspace
 \item Yes, This Computer Will Connect
  \subitem Through a Local Area Network or Home Network Option, 82
  \subitem Your Product Key dialog box, 78
\end{theindex}
Output of Index creation by using Keywords

– Setup Steps of theindex environment

The theindex environment sets up a convenient format for the index page. The entries and their corresponding page numbers are produced by the \MakeIndex program.

\MakeIndex acquires necessary inputs/entries from the TeX file in the form of unsorted keywords along with page numbers. In the main manuscript, the writers have to enter this information in the text file with the following command: \index{Entry_of_Index}

Here, Entry_of_Index refers to conceptual text which is required to be added into the index. You can combine alphabets, numbers, symbols, and even command characters and blanks. To use any command characters as an index entry, you have to enclose the command
within \verb.



Generally, LaTeX ignores the \index commands and certainly do not execute anything. To activate the index environment, you must include \makeindex in the preamble of your root TeX file. It will generate an index file *.idx (root texfile name.idx). Then, all of the \index commands of a manuscript record all index entry along with current page number to this *.idx file as shown below: \indexentry{index_entry}{correxponding_pagenumber}. Note that this .idx file is input file for the index creation process.

Disadvantages of Using theindex Macro

Handling indexes by \theindex is not an efficient method. Obviously generating and updating indexes according to keywords is a tedious task. It’s an old-fashioned manual procedure. The rate of observation of errors is very high in this procedure.

2. MakeIndex– Amazing Tool

Fortunately, an auxiliary program was written by Pehong Chen with the assistance of Leslie Lamport for LaTeX users. This package/program is well-known as MakeIndex. MakeIndex produce an *.idx file from provided information, those are gathered by index command from TeX documents

– How to Use and Run MakeIndex

To use MakeIndex, a user needs to follow the following steps:

  • Add \usepackage{makeidx} in the preamble of the root/main TeX file. Another package named imakeidx is also available for MakeIndex program. The difference is that imakeidx is more flexible and offer more customization option. To use this package instead, you have to add \usepackage{imakeidx} command at the preamble.
  • Add \makeindex in the preamble, just before \begin{document} is suggested.
  • \printindex where a user wants the index to appear. Usually, it is suggested to place just right before \end{document} command.
%%Sample snippet of Code and Output
\documentclass{article}

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

\begin{document}
\tableofcontents
\section{Introduction}
You may have several mobile devices that you want to
\index{sync} with windows 7.\index{remote} devices are seen
by \index{Windows} 7 as removable \index{storage devices}.
...........
\section{Next section}
The primary \index{SATA} disk drive on your personal Windows 7
computers is filling up. This drive contains the computer’s
\index{Windows!operating system} and application of software.

\printindex

\end{document}

Output:

Let suppose, your root TeX name is mainfile.tex. When you run the mainfile.tex file, it invokes MakeIndex to process a main.idx file. This file collects the entire information from all \index commands. Then, while you next run Makeindex by typing makeindex main command, it reads mainfile.idx file and produces as output another file mainfile.ind (root tex file name with extension.ind , such as mainfile.ind). It will not be accepted as an index entry, And the compiler also generate a warning regarding error. By reading the index, you can discover additional errors. They should be corrected by changing the appropriate \index commands in the document and regenerate the mainfile.ind file.

– How to Organize Entries

The MakeIndex program accepts its entries as one of the following forms:

Index Entry TypeLaTeX ExpressionExample
Main index entry\index{main_index_ent}\index{scheduling}
Sub-index entry\index{main_index_ent!sub_ent}\index{scheduling!reg}
Sub-sub-index entry\index{main_index_ent!sub_ent!sub_sub_ent}{\index{scheduling!reg!MS}

LaTeX and MakeIndex support only three levels of indexing. To specify a page number range, you need to put \index{…|(} command at the beginning of the page range and \index{…|)} at the end of the range.

Adding Cross-Reference on Index Entry

To add a cross-reference to another entry, you need to write an index entry as follows:

Format: \index{partitions}
\index{partitions!harddrive|see{harddrive,partitions}}
The primary \index{SATA} disk drive on your personal Windows 7
computers is filling up. This drive contains the computer’s
\index{Windows!operating system} and application of software.
\index{harddrive}
\index{partitions!harddrive|see{harddrive, partitions}}

Output:

– Adding String Format Entry

If a user needs to specify an entry or it’s sub-entry of the form, string1@string2, the first string determines the alphabetical position of the entry, while the second string produces the text of the entry.

Format:\index{SATA} \index{SATA@drive}
As The primary \index{SATA} disk drive on your personal Windows 7....
A \index{SATA@drive} drive in a computer that already has an
IDE drive installed, as long as your \index{motherboard}
supports both standards.
.......................
For example, \index{dynamic RAM|(} \index{dynamic RAM|)}

Output:

This property is pretty useful. The argument of an \index{} command provides the actual input string that LaTeX uses to generate the index entry.

For example, the commands \index{Gamma@$\gamma$}, \index{gms@\textbf{gms}} will generate a gamma entry in the index, but that entry would be alphabetized according to γ.

\index{Gammas}
\index{Gamma}
\index{Gamma@$\gamma$}
\index{gms@\textbf{gms}}

Output:

– Special Format Page numbers

Sometimes, indexes require a special page number format. As an example, you can use italic font to present primary references. Or an f after a page number to refer to an index entry of footnote. MakeIndex makes it more easier to implement such cases.

For any string (such as string_name), the command \index{…|string_name} prints a page number of the from \string_name{ref_n}. On the same way, to print any page number as the form \string_name{n-m}, or of the form \string_name{n} if the specified range includes only a single number, you would use the command \index{…|(string_name}.

\documentclass{article}

\usepackage{makeidx}
\newcommand{\nn}[1]{#1f}
\makeindex

\begin{document}
\tableofcontents
\section{Second section}
This second section\index{section} may include some special
word, and expand the ones already used\index{keywords!used}.
\index{Memory Card|emph}
\index{Memory|nn}
\index{Extra Space}
\index{Extra space|(emph}
\newpage
Some text here........
\newpage
...........................
\newpage
\index{Extra space|)}Again text ........
\printindex
\end{document}

Output:

– Parameters for makeindex command

  • title: To set a “Index Title” at the beginning of the index list of the document.
  • intoc: To include the title of the index at the “Table of Contents”.
  • columnskey_value: To specify the number of the columns for displaying index entries. Here, key_value must be an Integer. Note that, it’s default value is 2.
  • columnsep=Key To specify units for represent the separation between the columns. columnseprule To display a vertical line between the columns.

How to Add an Index in Table of Contents

You can include a list of index of a document in the “Table of contents”. One of the simplest way is to modify \makeindex command’s parameters in the preamble, if you would use makeidx package. For example:

\usepackage{makeidx}
\makeindex[intoc]

In above code snippet, intoc option is responsible for this inclusion. Similarly, the imakeidx package users have to use the same macro. For imakeidx package:

\usepackage{imakeidx}
\makeindex[intoc]

If you want to use TOC into tocbibind or idxlayout layouts of the makeidx package, then it is suggested to add the following environments into the preamble:

  • For tocbibind Layout: \usepackage[nottoc]{tocbibind}
  • For idxlayout Layout: \usepackage[totoc]{idxlayout}

At this level, we have reached the end of this tutorial about creating Index page.

Recent Posts