\nameref -- How to display section name AND its number
How about defining a new command \fullref
:
\documentclass{article}
\usepackage[colorlinks=true]{hyperref}
% Original definition
% \newcommand\fullref[1]{\autoref{#1} \nameref{#1}} % Two links
% Updated definition, see explanation below
\newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}} % One single link
\begin{document}
\section{First Section}
\label{sec:some_sec}
\subsection*{Unnumbered subsection}
\label{sec:subsec}
[...]
As we defined in \fullref{sec:some_sec}, yada yada yada, see \fullref{sec:subsec}
\end{document}
Update
The \fullref
defined above produces two links, one by \autoref
, the other by \nameref
. Heiko Oberdiek suggests the following definition that combines the two into one single link:
\newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}}
Starting with @herr-k 's answer, I went a step farther and defined four (4) new commands: \secref
, \subsecref
, \subsubsecref
, and \parref
.
\newcommand*{\secref}[1]{\hyperref[{#1}]{Specification \thesection, \nameref*{#1}}}
\newcommand*{\subsecref}[1]{\hyperref[{#1}]{Section \thesubsection, \nameref*{#1}}}
\newcommand*{\subsubsecref}[1]{\hyperref[{#1}]{Section \thesubsubsection, \nameref*{#1}}}
\newcommand*{\parref}[1]{\hyperref[{#1}]{Section \theparagraph, \nameref*{#1}}}
Doing so allows me to customize how the hyperlink text displays for each level of my document. In my case, There's not a difference between the \subsecref
, \subsubsecref
, and \parref
other than the number that displays (e.g. 1.1 vs 1.1.1 vs 1.1.1.A), but one can change these commands to suit their needs.