更新

更新

该按钮[Go To Summary]应该是指向摘要页面的链接,并且该[Go Back]按钮应该执行返回到上一个位置的命令。

这对于文件导航非常有用,因为我可以自由地从摘要移动到任何地方,并从任何地方返回到摘要或我之前所在的任何地方。

我创建了一个最小的乳胶文档来说明这一点:

\documentclass{article}

\usepackage{array}
\usepackage{hyperref}

\begin{document}

\tableofcontents

\section{Fermat’s Principle}

    \label{sec:fermat}
    Fermat’s principle states that the path light takes from one point
    to another is not necessarily the one with the smallest distance,
    but rather the path which can be traversed in the shortest time.


\section{Geometrical Optics}

    Geometrical optics is an approximation for light propagation in
    cases where the wavelength is very small compared to the
    structures with which the light interacts. Snell’s Law, describing
    refraction, can be derived from Fermat’s principle
    (see section~\ref{sec:fermat}).

\end{document}

这是链接内的说明性图片[Go To Summary] | [Go Back]。摘要是指Table of Contents或就Contents如图片所示:

在此处输入图片描述

返回功能很有用,因为大多数 PDF 视图的Go Back按钮可用性很差,很难找到它并单击它,只需一步即可。此外,[Go Back]除了它之外,链接也是必要的,[Go To Summary]因为你并不总是来自摘要,而是来自文档的另一部分,该部分有一个指向当前部分的链接,正如问题中教导的那样使用 hyperref 创建可点击的部分链接


更新

作为@Werner评论,似乎无法建立[Go Back]链接,因此仅[Go To Summary]链接就会有很大帮助。

在此处输入图片描述

答案1

以下示例允许您调整要与每个部分单元一起显示的文本,并提供返回到摘要/顶部/目录的单向链接:

在此处输入图片描述

\documentclass{article}

\usepackage{xcolor}
\usepackage[colorlinks]{hyperref}

\newcommand{\goToSummaryText}{\hyperlink{summary}{\textcolor{green}{\small\mdseries [Go To Top]}}}

\makeatletter
\newcommand{\addGoToSummary}{\renewcommand{\Sectionformat}[2]{##1 \goToSummaryText}}
\newcommand{\removeGoToSummary}{\renewcommand{\Sectionformat}[2]{##1}}
\makeatother

\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
  \hypertarget{summary}% Insert internal document link
  \oldtableofcontents}

\begin{document}

\tableofcontents

\addGoToSummary% Add "Go To Summary" to each section

\section{Fermat's Principle}\label{sec:fermat}
Fermat's principle states that the path light takes from one point
to another is not necessarily the one with the smallest distance,
but rather the path which can be traversed in the shortest time.

\removeGoToSummary% Remove "Go To Summary" from each section

\section{Geometrical Optics}
Geometrical optics is an approximation for light propagation in
cases where the wavelength is very small compared to the
structures with which the light interacts. Snell's Law, describing
refraction, can be derived from Fermat's principle
(see section~\ref{sec:fermat}).

\end{document}

答案2

合并@Werner回答,@touhami评论并给出答案:

  1. 使用 hyperref 时“返回”
  2. 如何改变一段文本的颜色?
  3. \Large 等字体大小是多少点(pt)?
  4. 如何在 (La)TeX 中插入管道符号?
  5. 为什么 abntex2 类在章节标题后插入新行?
  6. 如何修复转到摘要以便 \section[Some]{Some more} 不会抛出所有这些错误?
  7. 回忆录类中的“\Sectionformat”与“\Chapterformat”等效的是什么?
  8. 为什么 xapptocmd 要减少 \partname 和 \parttile 之间的垂直空间?

我添加了这个:

\definecolor{ultramarine}{RGB}{0,32,96}

\newcommand{\goToSummaryText}{{%
    \small\mdseries
    \hyperlink{summary}{\textcolor{ultramarine}{$\leftleftarrows$}}
    {$|$}
    \Acrobatmenu{GoBack}{\textcolor{ultramarine}{$\leftarrow$}}
}}

这是一个完整的例子:

\documentclass{article}
\usepackage{xcolor}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\definecolor{link_color}{RGB}{26,13,178}
\usepackage[backref,colorlinks,linkcolor=link_color]{hyperref}

\definecolor{ultramarine}{RGB}{0,32,96}
\RequirePackage{xpatch}
\RequirePackage{amssymb}
\newcommand{\goToSummaryText}{{%
    \small\mdseries
    \hyperlink{summary}{\textcolor{ultramarine}{$\leftleftarrows$}}
    {$|$}
    \Acrobatmenu{GoBack}{\textcolor{ultramarine}{$\leftarrow$}}
}}
\makeatletter
    \newif\ifismemoirloaded\ismemoirloadedfalse
    \newif\ifisabntexloaded\isabntexloadedfalse
    \@ifclassloaded{memoir}{%
        \ismemoirloadedtrue%
    }{}
    \@ifclassloaded{abntex2}{%
        \isabntexloadedtrue%
    }{}
    \newcommand{\addGoToSummary}
    {%
        \@ifundefined{printparttitle}{\message{printparttitle patch for addGoToSummary could NOT
                    be applied because there is no printparttitle command available!^^J}}{%
            \let\oldAddGoToprintparttitle\printparttitle
            \xapptocmd{\printparttitle}{~\protect\goToSummaryText}{}{}
        }
        \@ifundefined{Sectionformat}{\message{Sectionformat patch for addGoToSummary could NOT
                    be applied because there is no Sectionformat command available!^^J}}{%
            \let\oldAddGoToSectionformat\Sectionformat
            \xapptocmd{\Sectionformat}{~\protect\goToSummaryText}{}{}
        }
        \ifismemoirloaded
            \ifisabntexloaded
                \let\oldAddGoToABNTEXchapterupperifneeded\ABNTEXchapterupperifneeded
                \xapptocmd{\ABNTEXchapterupperifneeded}{~\protect\goToSummaryText}{}{}
            \else
                \let\oldAddGoToprintchaptertitle\printchaptertitle
                \xapptocmd{\printchaptertitle}{~\protect\goToSummaryText}{}{}
            \fi
        \else
            \@ifundefined{Chapterformat}{\message{Chapterformat patch for addGoToSummary could NOT
                        be applied because there is no Chapterformat command available!^^J}}{%
                \let\oldAddGoToChapterformat\Chapterformat
                \xapptocmd{\Chapterformat}{~\protect\goToSummaryText}{}{}
            }
        \fi
    }
    \newcommand{\removeGoToSummary}
    {%
        \@ifundefined{oldAddGoToprintparttitle}{}{\let\printparttitle\oldAddGoToprintparttitle}
        \@ifundefined{oldAddGoToSectionformat}{}{\let\Sectionformat\oldAddGoToSectionformat}
        \ifismemoirloaded
            \ifisabntexloaded
                \@ifundefined{oldAddGoToABNTEXchapterupperifneeded}{}{\let\ABNTEXchapterupperifneeded\oldAddGoToABNTEXchapterupperifneeded}
            \else
                \@ifundefined{oldAddGoToprintchaptertitle}{}{\let\printchaptertitle\oldAddGoToprintchaptertitle}
            \fi
        \else
            \@ifundefined{oldAddGoToChapterformat}{}{\let\Chapterformat\oldAddGoToChapterformat}
        \fi
    }
\makeatother
\let\oldAddGoTotableofcontents\tableofcontents
% Insert internal document link
\renewcommand{\tableofcontents}{%
    \hypertarget{summary}%
    \oldAddGoTotableofcontents%
}

\begin{document}

\tableofcontents
\addGoToSummary

\section{Fermat’s Principle}

    \label{sec:fermat}
    Fermat’s principle states that the path light takes from one point
    to another is not necessarily the one with the smallest distance,
    but rather the path which can be traversed in the shortest time.


\section{Geometrical Optics}

    Geometrical optics is an approximation for light propagation in
    cases where the wavelength is very small compared to the
    structures with which the light interacts. Snell’s Law, describing
    refraction, can be derived from Fermat’s principle
    (see section~\ref{sec:fermat}).

\end{document}

生成以下 PDF:

在此处输入图片描述

相关内容