
我無所事事地想知道而不是有see Section \ref{labelname}
產品
請參閱第 4.1.1 節
我可以做到這一點,以便see Section \ref{labelname}
產生
請參閱第 4.1.1 節(第 65 頁)
這可能嗎?使用會hyperref
搞砸嗎?
答案1
您可以定義一個命令,例如 \myref
\newcommand{\myref}[1]{\ref{#1} (p\pageref{#1})}
然後你可以使用\myref{xxx}
答案2
更乾淨的方法是像 的答案中使用新的巨集goodluck
。而且還\ref
可以重新定義。它應該盡可能晚地完成,因為許多包重新定義了它。在解決方案中,它是\AtBeginDocument
在前導碼的末尾完成的,特別是在hyperref
載入套件之後。
包還hyperref
支援星形形式,可以產生不含連結的參考。例如,如果引用是另一個引用的一部分,則這很有用,以避免嵌套連結。
\documentclass{article}
\usepackage{hyperref}
\makeatletter
\AtBeginDocument{%
\newcommand*{\original@ref}{}%
\let\original@ref\ref
\@ifpackageloaded{hyperref}{%
\renewcommand*{\ref}{%
\@ifstar\newrefstar\newref
}%
\newcommand*{\newrefstar}[1]{%
\original@ref*{#1} \textbf{(p\pageref*{#1})}%
}%
\newcommand*{\newref}[1]{%
\hyperref[#1]{\newrefstar{#1}}%
}%
}{%
\renewcommand*{\ref}[1]{%
\original@ref{#1} \textbf{(p\pageref{#1})}%
}%
}%
}
\makeatother
\begin{document}
\section{Introduction}
\section{Foo bar}
\subsection{Hello World}
\label{sec:hello}
This is subsection \ref{sec:hello}.
\end{document}
答案3
也許您想看看varioref
與其命令一起打包\vref
。這將產生您所需的輸出。此外,這不會影響您的hyperref
設定。