
hyperref
クリック可能なリンクがあるパッケージを使用しています\tableofcontents
。
強制する方法はありますか?1つ\tableofcontents
自動的に選択されたページではなく、特定のページを参照するためのハイパーリンクはありますか?
たとえば、PDF 出力の 2 ページ目から始まる章があり、目次で代わりに 3 ページ目を表示する対応するクリック可能なリンクを作成したいとします。
(ここでは一般的な答えを探しているので、コード/ヘッダーはありません)
答え1
おそらく私は質問を完全に誤解しているのでしょう:
hyperlink
章のエントリのように見えますが、章の開始ページではなく、別の場所を指している必要があります。
\nottocchapter
通常の番号付き章のように動作するが、そこから除外されるものを作成しました\addcontentsline
。
\lookslikeachapterentrybutpointstosomewhereelse
次に、関連する章のエントリを、表示されるページ番号とともに後で追加する (この名前は、適切なものを誤用するユーザーにとって面倒です ;-))を定義しました。
これをすべてお勧めしますか? いいえ ;-)
\documentclass{book}
\usepackage{blindtext}
\usepackage{xparse}
\makeatletter
\let\latex@chapter\chapter
\def\currentchaptername{}
\NewDocumentCommand{\notocchapter}{om}{%
\IfValueTF{#1}{%
\def\currentchaptername{#1}
}{%
\def\currentchaptername{#2}
}%
\begingroup
\renewcommand{\addcontentsline}[3]{}% Do nothing for this chapter
\IfValueTF{#1}{%
\latex@chapter[#1]{#2}
}{%
\latex@chapter{#2}
}%
\endgroup
}
\NewDocumentCommand{\lookslikeachapterentrybutpointstosomewhereelse}{o}{%
\phantomsection
\IfValueTF{#1}{%
\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
}{%
\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}\currentchaptername}
}%
}
\makeatother
\usepackage[linktocpage]{hyperref}
\begin{document}
\tableofcontents
\notocchapter{Some chapter}
\blindtext[20]
\lookslikeachapterentrybutpointstosomewhereelse
\chapter{Some other chapter}
\notocchapter{Another chapter}
\blindtext[40]
\lookslikeachapterentrybutpointstosomewhereelse[And now for something completely different]
\end{document}