![如何在 \ref{myRef} 前面添加链接文本?](https://linux22.com/image/260020/%E5%A6%82%E4%BD%95%E5%9C%A8%20%5Cref%7BmyRef%7D%20%E5%89%8D%E9%9D%A2%E6%B7%BB%E5%8A%A0%E9%93%BE%E6%8E%A5%E6%96%87%E6%9C%AC%EF%BC%9F.png)
我目前正在做这样的参考:
\section{BliBlaBlup} \label{sec:BliBlaBlup}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pharetra
pharetra viverra. Vestibulum ante ipsum primis in faucibus orci luctus et
ultrices posuere cubilia Curae; Suspendisse potenti. Curabitur mollis cursus
libero, sed tempus ligula accumsan in. Nulla commodo metus quis nulla luctus
quis euismod diam tincidunt.
[...]
As you can read in section~\ref{sec:BliBlaBlup} ...
现在,只有生成的数字\ref{sec:BliBlaBlup}
是链接的。但我希望有Section~\ref{sec:BliBlaBlup}
链接。我该怎么做?
答案1
\autoref
section
默认为小写\autoref
。但可以更改:
\usepackage{hyperref}
\renewcommand*{\chapterautorefname}{Chapter}
\renewcommand*{\sectionautorefname}{Section}
% ...
\begin{document}
...
As you can read in \autoref{sec:BliBlaBlup} ...
\hyperref[]
或者手动:
\usepackage{hyperref}
% ...
\begin{document}
...
As you can read in \hyperref[sec:BliBlaBlup]{Section~\ref*{sec:BliBlaBlup}} ...
星号形式\ref*{...}
避免了嵌套链接。
答案2
您可以使用以下\autoref
功能hyperref
:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\section{Blip}\label{blip}
What's this? A reference to \autoref{blip}.
\end{document}
或者,如果您想要将名称大写并且不想摆弄hyperref
的设置,您可以使用cleveref
:
\documentclass{article}
\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}
\begin{document}
\section{Blip}\label{blip}
What's this? A reference to \Cref{blip}.
\end{document}