# Customizing header in index to include current index entry

I know that the header can be be customized using various packages; not the least of which is fancyhdr.

In the index of my document, I would like to have the current "topic" of the index shown in he header. This is similar to having the current chapter shown in the header of the main body of the document.

Can someone show me how to do this?

• Please give us an MWE which shows your index and a chapter with appearance in the header. – LaRiFaRi Sep 14 '15 at 14:27
• With other words: You want to have the section (or chapter) title accompanying the index entry, say foo (Theory) or foo (This is my section title)? in your \printindex? – user31729 Sep 14 '15 at 16:01
• @ChristianHupfer Close. I want the header to be the first topic on that page of the index. Like a dictionary: the header is the first/last entry on that page. – jlconlin Sep 14 '15 at 17:05

This will get you started

Step 1: you need an index style file - put this in the same folder as your tex file but you can specify that it goes elsewhere

Name the file (for this example) index_xstyle.ist

headings_flag 1
delim_0 "} \\dotfill " % Provide right brace for level_0 items when they have page number:
delim_1 " \\dotfill "
delim_2 " \\dotfill "
item_x1 "} \n  \\subitem " % Provide the right brace for level_0 items when they have no page number:
item_0 "\n \\item \\indexmark{"%added this with its usual default to mark it up


Step 2: Try this mwe

If using other features of imakeidx such as split indices then compile with --shell-escape

\documentclass[a4paper]{article}
\usepackage{imakeidx}
\usepackage{fancyhdr}
\usepackage{hyperref}

%You need to make an index style
\fancypagestyle{index}{%
}

%You need a macro to use in your index style file to collect the index marks
\newcommand{\indexmark}[1]{#1\markboth{#1}{#1}}

%Set up your index (say to use your style on page 1 of index too if desired)
\indexsetup{level=\section*,toclevel=section,firstpagestyle=index}
%You need to tell it to use your style file
\makeindex[columns=2,title=Main index,intoc,options={-s index_xstyle.ist},]

\begin{document}

%Lots of index entries

%Set index pagestyle
\pagestyle{index}
\printindex
\end{document}


(Note: There are a few extra bits in the style file that I left in place to show how to place other items within style and grab the marks at the same time - remove them if required -- these are the dotfill and also some alpha headings)

• Why xelatex? ;-) – user31729 Sep 14 '15 at 18:23
• Because that is what I tested it with (doubt it will be a problem with anything else) – Aubrey Blumsohn Sep 14 '15 at 18:25
• @Jeremy would be great if you could let me know if this is useful (or why not useful) and mark accordingly so I will know I have not wasted an extended part of my life on this. – Aubrey Blumsohn Sep 16 '15 at 11:35
• @AubreyBlumsohn Thanks for the response. Something came up and I have not had a chance to implement this. Sorry. I will look at this. – jlconlin Sep 16 '15 at 12:54
• Thanks a lot. This worked well. Sorry again for the slow response. – jlconlin Sep 22 '15 at 15:32