Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to add the \indexname to the table of contents and to the bookmarks.

Now, I know one way to do this job: add the follow code before \printindex:

\phantomsection
\cleardoublepage
\addcontentsline{toc}{chapter}{\indexname}

but I want to move all the styling or customize code to single one .sty file

Anybody knows how to do this through renew \printindex command or some method can define in a .sty file?

EDIT: add the MWE

\documentclass{book}
\usepackage{makeidx}
\usepackage{hyperref}
\usepackage{lipsum}


\makeindex
\begin{document}

\frontmatter
\tableofcontents


\mainmatter
\chapter{one}
\lipsum[1]
\index{word}

\backmatter
\appendix
\phantomsection
\cleardoublepage
\addcontentsline{toc}{chapter}{\indexname}
\printindex


\end{document}
share|improve this question
2  
Based on your loaded packages and document class. Please provide a minimal working example. (Use \phantomsection after cleardoublepage. –  Marco Daniel May 26 '12 at 13:14
1  
The package tocbibind allows for automatic insertion. Also idxlayout and imakeidx do, though with different ways and purposes. –  egreg May 26 '12 at 13:18
    
possible duplicate of Index is incorrectly listed in the table of contents –  lockstep May 26 '12 at 13:20
    
@lockstep: Nor really. It depends on the package and class. For example in your linked question is no KOMA support or imakeidx, –  Marco Daniel May 26 '12 at 13:29
    
@MarcoDaniel My idxlayout package does support KOMA-Script and memoir. –  lockstep May 26 '12 at 13:30

2 Answers 2

up vote 10 down vote accepted

Three ways.

  1. tocbibind

    \usepackage{makeidx}
    \makeindex
    \usepackage[nottoc]{tocbibind}
    
  2. idxlayout

    \usepackage{makeidx}
    \makeindex
    \usepackage[totoc]{idxlayout}
    
  3. imakeidx

    \usepackage{imakeidx}
    \makeindex[intoc]
    

With methods 2 and 3 you have also that the last page of the index is balanced.

share|improve this answer

I've struggled with the very same problem, trying to make tocbibind make what I wanted it to. (add Index to TOC). Unfortunately with the above tocbibind-answer, the link (using hyperref) jumps to the chapter before the index. In my case, this is the bibliography. I fixed this by editing the tocbibind.sty file (you can probably do this in your own .sty-file). However, this solution requires the multicol package.

First of all, I added the following line after ProvidesPackage :

\RequirePackage{multicol}

Then, I re-defined the \printindex command, which adds a \chapter or \chapter* in front of the nidex environment (I think the actual pain in the a** is that the generated .ind file only holds the theindex environment and no command for adding the chapter/section/ other caption):

\if@inltxdoc\else
  \renewcommand{\printindex}{
    \if@bibchapter
      \if@donumindex
        \chapter{\indexname}
      \else
        \chapter*{\indexname}
          \if@dotocind
            \addcontentsline{toc}{chapter}{\indexname}
          \fi
        \fi
      \fi
    \addcontentsline{toc}{chapter}{\indexname}
    \@input@{\jobname.ind}
  }
\fi

Finally, in the code renewing the theindex environment I deleted the stuff from the \if@bibchapter branch (which now only reads \begin{multicols}{2}) and added the according \if@bibchapter\end{multicols}\fi into the environment's ending code:

\if@inltxdoc\else
  \renewenvironment{theindex}%
    {\if@twocolumn
       \@restonecolfalse
     \else
       \@restonecoltrue
     \fi
     \if@bibchapter
        \begin{multicols}{2}
     \else
        \if@donumindex
          \twocolumn[\vspace*{-1.5\topskip}%
                     \@nameuse{\@tocextra}{\indexname}]%
          \csname \@tocextra mark\endcsname{\indexname}
        \else
          \if@dotocind
            \twocolumn[\vspace*{-1.5\topskip}%
                       \toc@headstar{\@tocextra}{\indexname}]%
            \prw@mkboth{\indexname}
            \addcontentsline{toc}{\@tocextra}{\indexname}
          \else
            \twocolumn[\vspace*{-1.5\topskip}%
                       \toc@headstar{\@tocextra}{\indexname}]%
            \prw@mkboth{\indexname}
          \fi
        \fi
     \fi
   \thispagestyle{plain}\parindent\z@
   \parskip\z@ \@plus .3\p@\relax
   \let\item\@idxitem}
   {\if@bibchapter\end{multicols}\fi\if@restonecol\onecolumn\else\clearpage\fi}
\fi

Now the index page has the very same chapter caption and the hyperref link works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.