
我正在設計一本帶有詳細目錄的書。我想保持目錄的原樣,但希望透過將章節分組在一起,使 PDF 中的書籤不那麼擁擠。
微量元素:
\usepackage[utf8]{inputenc}
\usepackage[hidelinks, bookmarksopen=false]{hyperref}
\usepackage{bookmark}
\title{Question PDF bookmarks}
\author{Alex Dijk}
\date{April 2022}
\begin{document}
\chapter{1 jan}First January lecture
\chapter{2 jan}Another January lecture
\chapter{3 jan}Another January lecture
\chapter{4 jan}Another January lecture
\chapter{5 jan}Another January lecture
\chapter{6 jan}Another January lecture
\chapter{7 jan}Another January lecture
\chapter{8 jan}Another January lecture
\chapter{1 feb}First February lecture
\chapter{2 feb}Another February lecture
\chapter{3 feb}Another February lecture
\chapter{4 feb}Another February lecture
\chapter{5 feb}Another February lecture
\chapter{6 feb}Another February lecture
\chapter{7 feb}Another February lecture
\chapter{8 feb}Another February lecture
\end{document}
因此,在這裡,我想將名為“January”和“February”的書籤添加到生成的 PDF(但不添加到目錄)中。預設情況下,這些附加書籤需要處於未開啟狀態,所有一月和二月的單獨章節都將在這些書籤下排序。我該如何實現這個目標?
答案1
使用目前的 hyperref,您可以執行此操作(目前的 Latex 中不再需要 inputenc,無論如何, utf8 是幾年前的預設值):
\documentclass{book}
\usepackage[hidelinks, bookmarksopen=false]{hyperref}
\usepackage{bookmark}
\title{Question PDF bookmarks}
\author{Alex Dijk}
\date{April 2022}
\begin{document}
\bookmark[level=part,dest=\hyperget{anchor}{chap:jan}]{January}
\chapter{1 jan}\label{chap:jan}First January lecture
\chapter{2 jan}Another January lecture
\chapter{3 jan}Another January lecture
\chapter{4 jan}Another January lecture
\chapter{5 jan}Another January lecture
\chapter{6 jan}Another January lecture
\chapter{7 jan}Another January lecture
\chapter{8 jan}Another January lecture
\cleardoublepage
\bookmark[level=part,dest=\hyperget{anchor}{chap:feb}]{February}
\chapter{1 feb}\label{chap:feb}First February lecture
\chapter{2 feb}Another February lecture
\chapter{3 feb}Another February lecture
\chapter{4 feb}Another February lecture
\chapter{5 feb}Another February lecture
\chapter{6 feb}Another February lecture
\chapter{7 feb}Another February lecture
\chapter{8 feb}Another February lecture
\end{document}
在舊系統上,您必須手動建立目標:
\documentclass{book}
\usepackage[hidelinks, bookmarksopen=false]{hyperref}
\usepackage{bookmark}
\title{Question PDF bookmarks}
\author{Alex Dijk}
\date{April 2022}
\begin{document}
\hypertarget{jan}{}
\bookmark[level=part,dest=jan]{January}
\chapter{1 jan}First January lecture
\chapter{2 jan}Another January lecture
\chapter{3 jan}Another January lecture
\chapter{4 jan}Another January lecture
\chapter{5 jan}Another January lecture
\chapter{6 jan}Another January lecture
\chapter{7 jan}Another January lecture
\chapter{8 jan}Another January lecture
\cleardoublepage
\hypertarget{feb}{}
\bookmark[level=part,dest=feb]{February}
\chapter{1 feb}\label{chap:feb}First February lecture
\chapter{2 feb}Another February lecture
\chapter{3 feb}Another February lecture
\chapter{4 feb}Another February lecture
\chapter{5 feb}Another February lecture
\chapter{6 feb}Another February lecture
\chapter{7 feb}Another February lecture
\chapter{8 feb}Another February lecture
\end{document}