我已经看到了pdf LaTeX文档,其中页面底部的页码是hyperref链接,单击它们会使您跳转到目录表。我没有tex文件,也无法从hyperref包中计算出它是如何完成的。谁能帮忙?
您可以在toc上设置锚点并重新定义\thepage
以链接到它。这是一个例子:
\documentclass{report}
\usepackage[colorlinks]{hyperref}
\renewcommand*{\contentsname}{\hyperlink{contents}{Contents}}
\renewcommand*{\thepage}{\hyperref[contents]{\arabic{page}}}
\begin{document}
\tableofcontents
\chapter{One}
Text
\end{document}
如果使用babel并希望重新定义\contentsname
,请使用babel的\addto
命令或在\contentsname
之后重新定义\begin{document}
。
您是否尝试过以此定义页面编号?
\pagestyle{myheadings}
\markright{ ... }
其中\ markright指定页码,并带有指向内容页面的链接。
这是我的做法
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass[UTF8, english]{article}
\usepackage{lipsum} %% produce dummy texts
\usepackage[bookmarks = false, colorlinks = false, pdfborderstyle ={/S/D}]{hyperref}
\usepackage[pagestyles]{titlesec}
\newpagestyle{article}{
\headrule
\sethead
%% even pages
[\footnotesize \slshape \thesection. \textsc{\sectiontitle}]
[]
[]
%% odd pages
{}
{}
{\footnotesize \slshape \thesection. \textsc{\sectiontitle}}
%\footrule
\setfoot
%% even pages
[\footnotesize \usefont{OT1}{ptm}{m}{bf} \hyperlink{toc}{toc}]
[]
[\footnotesize \usefont{OT1}{ppl}{m}{it} example]
%% odd pages
{\footnotesize \usefont{OT1}{ppl}{m}{it} example}
{}
{\footnotesize \usefont{OT1}{ptm}{m}{} \hyperlink{toc}{toc}}
}
\begin{document}
\title{example}
\date{}
\author{author}
\maketitle
\pagenumbering{roman}
\setcounter{tocdepth}{2}
\addtocontents{toc}{\protect\hypertarget{toc}{}}
\tableofcontents
\newpage
\pagenumbering{arabic}
\pagestyle{article}
\section{A}
\lipsum[1]
\subsection{a}
\lipsum[2]
\subsection{b}
\lipsum[3]
\subsection{c}
\lipsum[4]
\section{B}
\lipsum[5]
\subsection{d}
\lipsum[6]
\subsection{e}
\lipsum[7]
\section{C}
\lipsum[8]
\subsection{f}
\lipsum[9]
\subsection{g}
\lipsum[10]
\subsection{h}
\lipsum[11]
\end{document}
您可以自定义链接文本回到目录,但是您喜欢在序言中使用。