# \nameref -- How to display section name AND its number

Is it possible to make \nameref display not only the title of the section but also its number?

\section{First Section}
\label{sec:some_sec}

\subsection*{Unnumbered subsection}
\label{sec:subsec}

[...]



With normal \nameref I get:

what I want is a combination of numbers (as in \autoref} and section names AND (if possible) unnumbered subsections should inherit the number of the parenting section:

• section~\ref{sec:some_sec} \nameref{sec:some_sec} Jun 30, 2013 at 18:05
• Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. Jun 30, 2013 at 18:18
• Your label {sec:subsec} has a negative effect. You are using \subsection* and so there is no anchor (number) for any label. Jun 30, 2013 at 18:55
• Marco, the answer works as I described above. For un-numbered subsections the number of the parenting section should be used -- and this is the case. Also, when i click the text in the PDF I get to the subsection (as expected). Thats exactly what I wanted ;) Jun 30, 2013 at 19:02

How about defining a new command \fullref:

\documentclass{article}

% 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}

[...]

\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}}}

• You get a full link in one piece by \newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref{#1}}}. Jun 30, 2013 at 21:14
• I have added the star for \nameref that I have forgotten in the comment. The star forms prevent nested double links. Jun 30, 2013 at 23:32
• Don't you need to add \usepackage{nameref} for this to work? Jan 13, 2015 at 13:29
• It conflicts with the titlesec package. The reference prints things like "chapter 2" instead of the name of the section. Nov 23, 2016 at 9:30
• @HeikoOberdiek if I want to capitalize the first letter, can I use \newcommand*{\fullref}[1]{\hyperref[{#1}]{\Cref*{#1} \nameref*{#1}}} with cleveref package or is there a better way?
– Diaa
Apr 29, 2017 at 7:32

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.