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

发布于 2024-09-12 18:12:38 字数 100 浏览 2 评论 0原文

我看过一个 pdf LaTeX 文档,其中页面底部的页码是超引用链接,单击它们会使您跳转到目录。我没有 tex 文件,无法弄清楚它是如何从 hyperref 包中完成的。有人可以帮忙吗?

I've seen a pdf LaTeX document where the page numbers at the bottom of the page are hyperref links, and clicking them causes you to jump to the contents table. I don't have the tex file and couldn't work out how it's done from the hyperref package. Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

长发绾君心 2024-09-19 18:12:38

您可以在目录中设置一个锚点并重新定义 \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{文档}

You could set an anchor at the toc and redefine \thepage to link to it. Here's an example:

\documentclass{report}
\usepackage[colorlinks]{hyperref}
\renewcommand*{\contentsname}{\hyperlink{contents}{Contents}}
\renewcommand*{\thepage}{\hyperref[contents]{\arabic{page}}}
\begin{document}
\tableofcontents
\chapter{One}
Text
\end{document}

If you use babel and wish to redefine \contentsname, use the \addto command of babel or redefine \contentsname after \begin{document}.

夕嗳→ 2024-09-19 18:12:38

您是否尝试过使用它来定义页码?

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

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

Have you tried defining the page numbering using this?

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

where \markright specifies the page number with a link to the content page.

鹿! 2024-09-19 18:12:38

这是我的做法,

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass[UTF8, english]{article}
\usepackage{lipsum} %% produce dummy texts

\usepackage{hyperref}
\usepackage[pagestyles]{titlesec}

\newpagestyle{article}{
\setfoot
%% even pages
[]
[\footnotesize \hyperlink{toc}{\thepage}]
[]
%% odd pages
{}
{\footnotesize \hyperlink{toc}{\thepage}}
{}
}

\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}

您当然可以在序言中将链接文本自定义回目录,请阅读 titlesec 了解更多详细信息。

Here is how I did it

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass[UTF8, english]{article}
\usepackage{lipsum} %% produce dummy texts

\usepackage{hyperref}
\usepackage[pagestyles]{titlesec}

\newpagestyle{article}{
\setfoot
%% even pages
[]
[\footnotesize \hyperlink{toc}{\thepage}]
[]
%% odd pages
{}
{\footnotesize \hyperlink{toc}{\thepage}}
{}
}

\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}

you can of course customize the link text back to table of contents however you like in the preamble, please read documentation of titlesec for more details.

不语却知心 2024-09-19 18:12:38

这对我有用。

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

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

另请参阅:https://tex.stackexchange.com/questions/227356/how-can-i-get-page-numbers-to-link-to-the-table-of-contents-in-latex

This worked for me.

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

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

See also: https://tex.stackexchange.com/questions/227356/how-can-i-get-page-numbers-to-link-to-the-table-of-contents-in-latex

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文