创建指向当前章节/节的超链接

创建指向当前章节/节的超链接

我想要一种方法来创建一个指向当前章节或章节开头的超链接,它具有与使用\label{section}and相同的效果,但不必使用。\ref{section}hyperref\label

以下是 MWE:

\documentclass[10pt,a5paper]{report}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage[linktoc=all,hidelinks,bookmarksnumbered,pagebackref,xetex]{hyperref}


\begin{document}
\chapter{Chapter 1}
\lipsum[1-2]

\section{Section 1}
\lipsum[3-5]

\section{Section 2}
\lipsum[6]
\textbf{Link to current section.}\\
\textbf{Link to current chapter.}\\
\lipsum[6]
\end{document}

答案1

像这样吗?

\documentclass[10pt,a5paper]{report}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage[linktoc=all,hidelinks,bookmarksnumbered,pagebackref,xetex]{hyperref}


\begin{document}
\chapter{Chapter 1}\hypertarget{chapter::\theHchapter}{}%
\lipsum[1-2]

\section{Section 1}
\lipsum[3-5]

\section{Section 2}\hypertarget{section::\theHsection}{}%
\lipsum[6]
\hyperlink{section::\theHsection}{\textcolor{blue}{Link to current section.}}
\hyperlink{chapter::\theHchapter}{\textcolor{blue}{Link to current chapter.}}
\lipsum[6]



\chapter{Chapter 1}\hypertarget{chapter::\theHchapter}{}%
\lipsum[1-2]

\section{Section 1}
\lipsum[3-5]

\section{Section 2}\hypertarget{section::\theHsection}{}%
\lipsum[6]
\hyperlink{section::\theHsection}{\textcolor{blue}{Link to current section.}}
\hyperlink{chapter::\theHchapter}{\textcolor{blue}{Link to current chapter.}}
\lipsum[6]

\end{document}

相关内容