我怎样才能让页码链接到乳胶中的目录?

我怎样才能让页码链接到乳胶中的目录?

只是想问一个四年前的问题:

“我见过一个 pdf LaTeX 文档,页面底部的页码是超链接,单击它们会跳转到目录。我没有 tex 文件,无法弄清楚如何从超链接包中完成此操作。有人可以帮忙吗?” https://stackoverflow.com/questions/3393606/how-can-i-get-page-numbers-to-link-to-the-table-of-contents-in-latex

这正是我想要的。不幸的是,这些答案都行不通。当然,我可以在每一页都放一个“\hyperref”,但如果我有一篇 100 站点的文章,那将需要相当长的时间。

编辑:

\documentclass[10pt,a4paper,colorlinks]{article}
\usepackage[german]{babel} 
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry} 
\usepackage{hyperref} 
\usepackage{tocloft}
\usepackage{lipsum}
\begin{document}
\tableofcontents
\thispagestyle{empty} 
\setcounter{page}{0} 
\newpage
\section{Text 1}
\lipsum{1}
\newpage
\section{Text 2}
\lipsum{2}
\end{document}

希望我没有删除相关内容。设置

%\thispagestyle{empty} 
%\setcounter{page}{0} 

能够在第一页上看到首页的页码。

答案1

这有效:

\documentclass[10pt,a4paper,colorlinks]{article}
\usepackage[german]{babel}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{hyperref}
\usepackage{tocloft}
\usepackage{lipsum}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\ps@plain}{\thepage}{\hyperlink{contents}{\thepage}}{}{}
\makeatother
\addto\captionsgerman{\renewcommand*{\contentsname}{\hypertarget{contents}{Inhaltsverzeichnis}}}
\pagestyle{plain}
\begin{document}
\tableofcontents
\thispagestyle{empty}
\setcounter{page}{0}
\newpage
\section{Text 1}
\lipsum
\newpage
\section{Text 2}
\lipsum
\end{document} 

答案2

这对我有用。

% Make the page number link back to the table of contents
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\hyperlink{toc}{\thepage}}
\fancypagestyle{plain}{
    \fancyhf{}
    \fancyfoot[C]{\hyperlink{toc}{\thepage}}
}
...

\hypertarget{toc}{} % anchor for page number to link to
\tableofcontents

也可以看看:https://stackoverflow.com/questions/3393606/how-can-i-get-page-numbers-to-link-to-the-table-of-contents-in-latex

相关内容