Phantomsection 超链接问题

Phantomsection 超链接问题

我遇到了一个问题。超链接可以工作,但它跳转到页面中心,而不是标题名称 Index1 和 Index2。我做错了什么?我使用了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
    \addcontentsline{toc}{chapter}{Nomenclature}
    \printnomenclature[3,0 cm]

    \cleardoublepage
    \phantomsection
    \addcontentsline{toc}{chapter}{Index1}
    \printindex[Index1]

    \cleardoublepage
    \phantomsection
    \addcontentsline{toc}{chapter}{Index2}
    \printindex[Index2]

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

答案1

修补theindex命令。

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

\usepackage{etoolbox}
\makeatletter
\patchcmd{\theindex}
  {\@makeschapterhead}
  {\phantomsection
   \addcontentsline{toc}{chapter}{\indexname}%
   \@makeschapterhead}
  {}{}
\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
\addcontentsline{toc}{chapter}{Nomenclature}
\printnomenclature[3,0 cm]

\printindex[IndexTerms]

\printindex[IndexServs]

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

答案2

\phantomsection调用时页面上没有任何内容可链接。在它前面放一个空框。

\cleardoublepage
\mbox{}\phantomsection
\addcontentsline{toc}{chapter}{Nomenclature}

更好的选择是将术语表加到章节标题中,等等。

\cleardoublepage
\chapter*{Nomenclature}
\phantomsection
\addcontentsline{toc}{chapter}{Nomenclature}
\markboth{Nomenclature}{Nomenclature}

相关内容