有没有办法(自动)为索引的每个“部分”创建 pdf 书签?索引中的“部分”对应于字母表的每个字母。有道理吗?
有没有办法做到这一点?
最小工作示例:
\documentclass{article}
\usepackage{imakeidx}
\usepackage[colorlinks]{hyperref}
\makeindex
\title{An Example of an Article with an Index}
\begin{document}
\maketitle
Alligator\index{Alligator}
Bat\index{Bat}
Crocodile\index{Crocodile}
Dingo\index{Dingo}
Elephant\index{Elephant}
Frog\index{Frog}
Giraffe\index{Giraffe}
Horse\index{Horse}
Iguana\index{Iguana}
Jaguar\index{Jaguar}
Kangaroo\index{Kangaroo}
Lemur\index{Lemur}
Mongoose\index{Mongoose}
Newt\index{Newt}
Octopus\index{Octopus}
Penguin\index{Penguin}
Quail\index{Quail}
Rabbit\index{Rabbit}
Snake\index{Snake}
Turtle\index{Turtle}
Unicorn\index{Unicorn}
Velociraptor\index{Velociraptor}
Wildabeest\index{Wildabeest}
Xantus\index{Xantus}
Yak\index{Yak}
Zebra\index{Zebra}
\printindex
\end{document}
答案1
.ist
为此,您需要一个索引样式文件 ( )。但使用imakeidx
它可以轻松配置此文件:
\begin{filecontents*}{\jobname.ist}
headings_flag 1
heading_prefix "\\indexheading{"
heading_suffix "}"
\end{filecontents*}
\documentclass{article}
\usepackage{imakeidx}
\usepackage[colorlinks,bookmarks]{hyperref}
\newcommand*{\indexheading}[1]{%
\bigskip\noindent{\large\bfseries\pdfbookmark[1]{#1}{index.#1}#1\par}\nobreak
}
\makeindex[options={-s \jobname.ist}]
\title{An Example of an Article with an Index}
\begin{document}
\maketitle
Alligator\index{Alligator}
Bat\index{Bat}
Crocodile\index{Crocodile}
Dingo\index{Dingo}
Elephant\index{Elephant}
Frog\index{Frog}
Giraffe\index{Giraffe}
Horse\index{Horse}
Iguana\index{Iguana}
Jaguar\index{Jaguar}
Kangaroo\index{Kangaroo}
Lemur\index{Lemur}
Mongoose\index{Mongoose}
Newt\index{Newt}
Octopus\index{Octopus}
Penguin\index{Penguin}
Quail\index{Quail}
Rabbit\index{Rabbit}
Snake\index{Snake}
Turtle\index{Turtle}
Unicorn\index{Unicorn}
Velociraptor\index{Velociraptor}
Wildabeest\index{Wildabeest}
Xantus\index{Xantus}
Yak\index{Yak}
Zebra\index{Zebra}
\clearpage
\pdfbookmark[0]{\indexname}{\indexname}
\printindex
\end{document}
如果您不想要索引本身的大字母而只想要书签,您可以\indexhead
用以下方法替换上面示例中的定义:
\newcommand*{\indexheading}[1]{%
\pdfbookmark[1]{#1}{index.#1}%
}
注意:filecontents
环境仅在文件不存在时才会写入文件。如果您希望filecontents
环境覆盖现有文件,则应加载包文件内容前。