3

Possible Duplicate:
Index is incorrectly listed in the table of contents

I want to add a custom section to my table of contents. I know I can use addcontentsline{toc}{section}{title}. However, it doesn't use correct reference. When clicking on the item in the toc, it just jumps to the wrong section.

MWE:

\documentclass[a4paper]{scrartcl}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[pdftex,bookmarks=true,bookmarksnumbered,colorlinks=true]{hyperref} % http://ctan.org/pkg/hyperref
\usepackage{nameref}
\usepackage{makeidx}

\makeindex

\begin{document}
    \tableofcontents

    \section{Section 1}
    \index{bla}. \index{blub}.
    \section{Section 2}

    \addcontentsline{toc}{section}{Index}
    \printindex
\end{document}

To compile, run:

pdflatex file.tex
makeindex file
pdflatex file.tex
pdflatex file.tex

When clicking on Index it jumps to "2 Section 2" instead of "Index".

3
  • Issue \clearpage\phantomsection\addcontentsline{toc}{section}{Index}\printindex.
    – Werner
    Jun 15, 2012 at 23:06
  • \usepackage[nottoc]{tocbibind} takes care of the matter without any \addcontentsline command.
    – egreg
    Jun 15, 2012 at 23:08
  • Is tocbibind good for KOMA class as well?
    – cherrung
    Jun 15, 2012 at 23:27

1 Answer 1

4

Since you are using one of the KOMA-Script document classes, all you have to do is to add the index=totoc class option:

\documentclass[a4paper,index=totoc]{scrartcl}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[pdftex,bookmarks=true,bookmarksnumbered,colorlinks=true]{hyperref} % http://ctan.org/pkg/hyperref
\usepackage{nameref}
\usepackage{makeidx}

\makeindex

\begin{document}
    \tableofcontents

    \section{Section 1}
    \index{bla}. \index{blub}.
    \section{Section 2}

    \printindex
\end{document}

Not the answer you're looking for? Browse other questions tagged .