nameref 带有任意文本

nameref 带有任意文本

这是一个后续问题:文本内的交叉引用

@Werner 给出了一个很好的交叉引用 MWE,用于返回到文本中某个部分而不是该部分的开头。但是,“返回”链接仍然包含要返回的部分的名称。如何将任意文本放置在该“返回”链接中,或者更好的是,如何将引用的部分标题变成“返回”链接(而不显示在“引用”链接中)?类似这样:

\documentclass[onecolumn,twoside]{revtex4}

\usepackage{xpatch}% http://ctan.org/pkg/xpatch
\makeatletter
\xpatchcmd{\@ssect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}%    Patch \<section>*
\xpatchcmd{\@sect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}% Patch \<section>
\makeatother
\usepackage{hyperref}% http://ctan.org/pkg/hyperref

\hypersetup{pdfstartview=FitH,pdfpagemode=UseNone}

\begin{document}

\title{Title}
\author{Author}
\affiliation{Affiliation}

\maketitle

\section*{\texorpdfstring{FirstSection}{}}
 text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text   text text text text
\bf I want to return here, not at the beginning of FirstSection \rm      \nameref{sec:marker2} \phantomsection   \label{sec:marker1} (\bf the text CLICK HERE TO GO  BACK shouldn't show up here \rm)
text text text text text text text text text text text text text text text text text     text text text text text text text text text text text text text text text text     text text text text text text text text text text text text 

\section*{SecondSection--CLICK HERE TO GO BACK} \label{sec:marker2} 
You can also see in \nameref{sec:marker1} that \ldots
\end{document} 

答案1

为此,您可以使用\hyperref[<label>]{<text>}宏并在 中提供替代文本<text>。因此,对于您的情况,您可以使用

\hyperref[sec:marker2]{SecondSection}

这是带有修改后的超链接的最小示例:

在此处输入图片描述

\documentclass[onecolumn,twoside]{revtex4}

\usepackage{xpatch}% http://ctan.org/pkg/xpatch
\makeatletter
\xpatchcmd{\@ssect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}%    Patch \<section>*
\xpatchcmd{\@sect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}% Patch \<section>
\makeatother
\usepackage{hyperref}% http://ctan.org/pkg/hyperref

\hypersetup{pdfstartview=FitH,pdfpagemode=UseNone}

\begin{document}

\title{Title}
\author{Author}
\affiliation{Affiliation}

\maketitle

\section*{\texorpdfstring{FirstSection}{}}
 text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text   text text text text
\bf I want to return here, not at the beginning of FirstSection \rm      \hyperref[sec:marker2]{SecondSection} \phantomsection   \label{sec:marker1} (\bf the text CLICK HERE TO GO  BACK shouldn't show up here \rm)
text text text text text text text text text text text text text text text text text     text text text text text text text text text text text text text text text text     text text text text text text text text text text text text 

\section*{SecondSection--CLICK HERE TO GO BACK} \label{sec:marker2} 
You can also see in \nameref{sec:marker1} that \ldots
\end{document} 

相关内容