
我正在使用hyperref
包,以便它\tableofcontents
具有可點擊的連結。
有沒有辦法強制一超連結引用\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}