# Phantomsection hyperlink problem

I have a problem. The hyperlinks work but it jumps on the center of page and not on the title name Index1 and Index2. What did I do wrong? I use documentclass{book}.

    \documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[makeindex]{splitidx}
\usepackage{hyperref}

\newcommand{\ITerm}{IndexTerms}
\newcommand{\IServ}{IndexServs}
\newcommand{\MyLarge}{\Large}
\newcommand{\smindexxspecial}[2]{{\MyLarge#2} \sindex[#1]{#2}}
\newcommand{\smindexspecial}[2]{{\MyLarge#2}\sindex[#1]{#2}}
\newcommand{\smindexvspecial}[2]{{\MyLarge#2}\sindex[#1]{#2}}
\newcommand{\smsindexspecial}[2]{{\MyLarge \url{#2}}\sindex[#1]{#2}}

\makenomenclature
\newindex[General Index]{IndexTerms}
\newindex[Websites]{IndexServs}

\begin{document}

\smindexspecial{\ITerm}{blabla}
(\smsindexspecial{\IServ}{www.wikipedia.com})
\nomenclature{bla}{bla}

\tableofcontents

%other things they go to tableofcontent too

\backmatter
\cleardoublepage
\phantomsection
\printnomenclature[3,0 cm]

\cleardoublepage
\phantomsection
\printindex[Index1]

\cleardoublepage
\phantomsection
\printindex[Index2]

And this is the end of the story.
\end{document}

• What package are you using for multiple indices? – egreg Nov 4 '13 at 10:11
• @egreg \usepackage[makeindex, split]{splitidx} \usepackage{hyperref} – blue Nov 4 '13 at 10:18
• Can you add a minimal working example (MWE) to play with? – egreg Nov 4 '13 at 10:19
• @egreg I think it will be not the same, because I am creating a book.But I try do my best for creating a minimal working example. – blue Nov 4 '13 at 10:42
• @egreg I do mwe, but I am sure it will be not the same. – blue Nov 4 '13 at 11:02

Patch the theindex command.

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[makeindex]{splitidx}
\usepackage{nomencl}
\usepackage{hyperref}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\theindex}
{\phantomsection
{}{}
\makeatother

\newcommand{\ITerm}{IndexTerms}
\newcommand{\IServ}{IndexServs}
\newcommand{\MyLarge}{\Large}
\newcommand{\smindexxspecial}[2]{{\MyLarge#2} \sindex[#1]{#2}}
\newcommand{\smindexspecial}[2]{{\MyLarge#2}\sindex[#1]{#2}}
\newcommand{\smindexvspecial}[2]{{\MyLarge#2}\sindex[#1]{#2}}
\newcommand{\smsindexspecial}[2]{{\MyLarge \url{#2}}\sindex[#1]{#2}}

\makenomenclature
\newindex[General Index]{IndexTerms}
\newindex[Websites]{IndexServs}

\begin{document}

\smindexspecial{\ITerm}{blabla}
(\smsindexspecial{\IServ}{www.wikipedia.com})
\nomenclature{bla}{bla}

\tableofcontents

%other things they go to tableofcontent too

\backmatter
\cleardoublepage
\phantomsection
\printnomenclature[3,0 cm]

\printindex[IndexTerms]

\printindex[IndexServs]

And this is the end of the story.
\end{document}

• thank you. It works, but when I write after printindex \clearpage \phantomsection \addcontentsline{toc}{chapter}{References} it has not effect. It doesn't appear in table of content. When I write it befor printindex IndexTerms then is the hyperlink wronge. I have no idea how can I solve it.. – blue Nov 6 '13 at 18:57
• @blue I'm thinking you're using the wrong approach (and I already told you) with multiple indices. Anyway, your last comment is too vague. Please, if this answer works for the question you posed, write another question with the specific problem you're facing now. – egreg Nov 6 '13 at 20:46

There is nothing to link to on the page when \phantomsection is called. Put an empty box before it.

\cleardoublepage
\mbox{}\phantomsection

\cleardoublepage