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 index 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.
\phantomsection
aftercleardoublepage
.tocbibind
allows for automatic insertion. Alsoidxlayout
andimakeidx
do, though with different ways and purposes.KOMA
support orimakeidx
,idxlayout
package does support KOMA-Script andmemoir
.