在改Latex模板的时候发现了很多种生成pdf书签/目录/提纲的方法,这里稍微做一个整理。
假设Latex中已经生成多级标题,我们用命令:
\tableofcontents
可以生成目录,代码示例:
\documentclass[UTF8]{ctexart} \title{周总结24} \author{战忽局小可爱} \date{\today} % 页边距 \usepackage{geometry} \newgeometry{left = 3 cm, right = 3 cm, top=2.5cm, bottom=1.5cm} \begin{document} \maketitle{\textbf{Abstract}} ~\\ % 空一行 \tableofcontents % 生成目录 \section{Python} % 一级标题 \subsection{Leetcode} % 二级标题 \section{写作} % 一级标题 \section{其他} % 一级标题 \subsection{Latex} % 二级标题 \subsection{博客} % 二级标题 \end{document} 复制代码
可自动生成目录,如图下:
直接加一行命令:
\usepackage{hyperref}
可以生成pdf书签,代码如下:
\usepackage{hyperref} % 在\begin{document}之前加入 \begin{document} 复制代码
得到效果如图(背景色是Adobe Acrobat的护眼色):
这时候点书签的标题条目可以直接跳转到标题页
但是pdf文档中的目录有红框框,不好看,我们可以使用如下命令:
\usepackage{hyperref} %%%% 下面是新加的 %%%% \hypersetup{hidelinks, colorlinks=true, allcolors=black, pdfstartview=Fit, breaklinks=true } 复制代码
显示结果如下:
还有一种方法是使用命令:
\usepackage{pdfcomment}
代码:
\usepackage{pdfcomment} % 新写入 复制代码
或者可以这样:
\usepackage{pdfcomment} \newcommand{\commentontext}[2]{\colorbox{yellow!60}{#1}\pdfcomment[color={0.234 0.867 0.211},hoffset=-6pt,voffset=10pt,opacity=0.5]{#2}} \newcommand{\commentatside}[1]{\pdfcomment[color={0.045 0.278 0.643},icon=Note]{#1}} \newcommand{\todo}[1]{\commentatside{#1}} \newcommand{\TODO}[1]{\commentatside{#1}} 复制代码
\usepackage{pdfcomment} 跟 \usepackage{hyperref} 的区别我还不太清楚,但是显示效果两者基本上是一样的,如图下:
在这个环境下去掉红框,可以使用代码如下:
\usepackage{pdfcomment} \newcommand{\commentontext}[2]{\colorbox{yellow!60}{#1}\pdfcomment[color={0.234 0.867 0.211},hoffset=-6pt,voffset=10pt,opacity=0.5]{#2}} \newcommand{\commentatside}[1]{\pdfcomment[color={0.045 0.278 0.643},icon=Note]{#1}} \newcommand{\todo}[1]{\commentatside{#1}} \newcommand{\TODO}[1]{\commentatside{#1}} %\usepackage{hyperref} % 有了\usepackage{pdfcomment},这一句加不加都可以(吧) \hypersetup{hidelinks, colorlinks=true, allcolors=black, pdfstartview=Fit, breaklinks=true } 复制代码
效果如下:
如果要去掉书签,把上述出现的所有代码删掉即可