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.

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".

share|improve this question

marked as duplicate by egreg, percusse, Werner, Gonzalo Medina, Marco Daniel Jun 16 '12 at 7:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
add comment

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