Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

[...]

As we defined in section \nameref{sec:some_sec}, yada yada yada, see section \nameref{sec:subsec}

With normal \nameref I get:

"As we defined in section First Section, yada yada yada, see section Unnumbered subsection"

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:

"As we defined in section 1 First Section, yada yada yada, see section 1 Unnumbered subsection"

share|improve this question
3  
section~\ref{sec:some_sec} \nameref{sec:some_sec} –  egreg Jun 30 '13 at 18:05
    
Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. –  Claudio Fiandrino Jun 30 '13 at 18:18
1  
Your label {sec:subsec} has a negative effect. You are using \subsection* and so there is no anchor (number) for any label. –  Marco Daniel Jun 30 '13 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 ;) –  cpt. jazz Jun 30 '13 at 19:02
add comment

1 Answer

up vote 8 down vote accepted

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}

enter image description here


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}}}
share|improve this answer
4  
You get a full link in one piece by \newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref{#1}}}. –  Heiko Oberdiek Jun 30 '13 at 21:14
    
@HeikoOberdiek: Thanks :-) Your suggestion is incorporated. –  Kevin C Jun 30 '13 at 21:31
1  
I have added the star for \nameref that I have forgotten in the comment. The star forms prevent nested double links. –  Heiko Oberdiek Jun 30 '13 at 23:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.