没有章节编号,但仍然有带超链接的 PDF 书签

没有章节编号,但仍然有带超链接的 PDF 书签

我有一份包含多个章节的文档。我不希望章节编号显示在文档中,但我希望使用该hyperref包自动将章节显示为 PDF 中的书签。

我知道可以使用\section*命令来删除文档中的章节编号,但这也会删除书签。有什么折衷方案吗?

答案1

您可以抑制章节编号的出现:

\documentclass[a4paper]{article}
\usepackage{hyperref}
\usepackage{bookmark}
\makeatletter
\renewcommand\@seccntformat[1]{}
\makeatother

\begin{document}
\section{A}
a
\newpage
\section{B}
b
\end{document}

该宏\@seccntformat负责打印节号;通过将其重新定义为“不执行任何操作”,不会打印节号,但是超链接能够正确创建书签。

书签包是一个很好的附加组件,因为它避免了原始书签创建实现的一些弱点。

答案2

hyperref提供书签功能

\pdfbookmark[<level>]{<text>}{<name>}

或者

\currentpdfbookmark{<text>}{<name>}

除了其他(见hyperref文档)。下面是一个简单的例子:

在此处输入图片描述

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\begin{document}
\section*{First section} \pdfbookmark{First section}{sec:first} \lipsum[1]
\section*{Second section} \pdfbookmark{Second section}{sec:second} \lipsum[2]
\section*{Third section} \pdfbookmark{Third section}{sec:third} \lipsum[3]
\section*{Last section} \pdfbookmark{Last section}{sec:fourth} \lipsum[4]
\end{document}

可以将该形式作为部分命令的一部分\section

如果你只想要书签,而不太关心文档内部的超级引用,请使用bookmark包裹反而。

答案3

也可以完全关闭标题编号。由于您没有明确说明只想要未编号的部分,因此这可能是一种替代方法。

\documentclass[11pt,english]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{blindtext}
\usepackage{hyperref}

\setcounter{secnumdepth}{0}

\begin{document}
  \blinddocument
\end{document}

这样你就可以使用已知\section命令了。再次注意,这将关闭所有标题级别的编号。


在此处输入图片描述

答案4

这是一个非常简短的解决方案,不需要对序言进行任何更改,只要您正在加载hyperref

\section*{Acknowledgements}% The * makes this section unnumbered. 
\addcontentsline{toc}{section}{Acknowledgements}% This command makes the unnumbered section also appear in the pdf bookmarks.

注意:您不需要在文件开头调用目录来实现此功能。

相关内容