如何获得页码以链接到乳胶目录?

问题描述 投票:5回答:3

我已经看到了pdf LaTeX文档,其中页面底部的页码是hyperref链接,单击它们会使您跳转到目录表。我没有tex文件,也无法从hyperref包中计算出它是如何完成的。谁能帮忙?

latex hyperref
3个回答
2
投票

您可以在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}


0
投票

您是否尝试过以此定义页面编号?

\pagestyle{myheadings}
\markright{ ... }

其中\ markright指定页码,并带有指向内容页面的链接。


0
投票

这是我的做法

% !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}

您可以自定义链接文本回到目录,但是您喜欢在序言中使用。

© www.soinside.com 2019 - 2024. All rights reserved.