×

ShareLaTeX guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

In some big documents, for example books, is customary to make an alphabetic list containing the main terms. With L a T e X and the support program imakeindex , an index can be generated quite easily.

Contents

Introduction

Let's see a simple working example.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{imakeidx}
\makeindex
 
\begin{document}
 
\section{Introduction}
In this example several keywords\index{keywords} will be used 
which are important and deserve to appear in the Index\index{Index}.
 
Terms like generate\index{generate} and some\index{others} will 
also show up. 
 
\printindex
 
\end{document}

First, the package is included in the preamble by the line

\usepackage{imakeidx}


Then the command \makeindex is mandatory for the index to work and can take some parameters to customize its appearance, in the next sections this will be clear.

To add an entry to the index the command \index{} is used, passing as parameter to it the word to be added. Be careful, this won't print the word in the current position but only in the index.

Finally, the command \printindex will actually render the index. If you are using a special localization by means of the babel package the title will be translated accordingly.

Note: instead of imakeidx the package makeidx may be imported, but offers less customizations possibilities.

Open an example of the imakeidx package in ShareLaTeX

Entries and subentries

As mentioned in the previous section, the command \index will add the word passed to it to the index, but this is not the only way it can be used

\documentclass{article}
\usepackage{imakeidx}
\usepackage[utf8]{inputenc}
\makeindex
 
\begin{document}
 
\section{Introduction}
In this example several keywords\index{keywords} will be used 
which are important and deserve to appear in the Index\index{Index}.
 
Terms like generate\index{generate} and some\index{others} will also 
show up. Terms in the index can also be nested \index{Index!nested}
 
\clearpage
 
\section{Second section}
This second section\index{section} may include some special word, 
and expand the ones already used\index{keywords!used}.
 
\printindex
\end{document}

Is a common practice to extend terms in the index to include special adjectives. For instance, the word Field my have a special meaning if preceded by the adjective finite or followed by of characteristic 0 and it may be a bit cumbersome to add the word Finite several times in the index. For such cases you can add a exclamation mark "!" that will add the therms after this mark as sub entries of the main word.

In the example, the word "Index" has the word "nested" as sub entry.

Open an example of the imakeidx package in ShareLaTeX

Formatting the Index

Simple formatting for the index, such as changing the index title, adding several columns and changing the column width can be easily done passing optional values to \makeindex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=Alphabetical Index]
 
\begin{document}
 
\section{Introduction}
In this example several keywords\index{keywords} will be used which 
are important and deserve to appear in the Index\index{Index}.
 
Terms like generate\index{generate} and some\index{others} will also 
show up. Terms in the index can also be nested \index{Index!nested}
 
\clearpage
 
\section{Second section}
This second section\index{section} may include some special word, 
and expand the ones already used\index{keywords!used}.
 
\printindex
\end{document}

In this example the index is presented in a three-column format with the parameter columns=3 , and the title is changed to "Alphabetical Index" by title=Alphabetical Index ; these parameters are passed to \makeindex in the preamble. See the reference guide for a list of available parameters and their description.

Open an example of the imakeidx package in ShareLaTeX

Including the index in the table of contents

By default, the index is not included in the table of contents, this can easily reverted.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=Alphabetical Index, intoc]
 
\begin{document}
 
\tableofcontents
 
\section{Introduction}
In this example several keywords\index{keywords} will be 
used which are important and deserve to appear in the 
Index\index{Index}.
 
Terms like generate\index{generate} and some\index{others} 
will also show up. Terms in the index can also be 
nested \index{Index!nested}
 
\clearpage
 
\section{Second section}
This second section\index{section} may include some special 
word, and expand the ones already used\index{keywords!used}.
 
\printindex
\end{document}

By adding the parameter intoc to the command \makeindex the inclusion of the index title into the table of contents is enabled.

Open an example of the imakeidx package in ShareLaTeX

Reference guide

Parameters for the \makeindex command.

title
Title to be typeseted at the beginning of the specific index. An example is presented in formatting the index .
intoc
If this option is passed the index title is put in the table of contents .
columns
Uses the syntax key=value , the value must be an integer representing the number of columns. The default value is 2.
columnsep
Units that represent the separation between the columns. The syntax must be key=value , for example columnsep=2em .
columnseprule
Is this is set, a vertical ruler will be rendered between the columns.

Open an example of the imakeidx package in ShareLaTeX

Further reading

For more information see: