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.

I want my cross reference links to look like:

Chapter X: Chapter Title

To achieve that I have created the following command:

\newcommand{\fancyref}[1]{\autoref{#1}: \nameref{#1}}

The problem is that the : character is not part of the generated hyperlink.

Could someone help?

Thanks in advance.

Warning I get when compiling Leo Liu's example:

LaTeX Warning: Reference `*' on page 1 undefined on input line 10.

[1{/usr/local/texlive/2009/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./example.aux)

LaTeX Warning: There were undefined references.
share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

I think you can use:

\hyperref[label]{\autoref*{label}: \nameref*{label}}

Full example:

\documentclass{article}
\usepackage{hyperref,nameref}
\newcommand\myref[1]{%
  \hyperref[#1]{\autoref*{#1}: \nameref*{#1}}}

\begin{document}
\section{Foo}
\label{sec:foo}

\myref{sec:foo}
\end{document}
share|improve this answer
    
It didn't quite work for me. It is giving fata errors. I think the problem is the * how can I have the * in a newcommand definition? –  Tiago Veloso Jan 17 '11 at 17:51
    
@Tiago: I add a full example works for me. Check your code if there is something wrong. The * avoids a hyper link here. –  Leo Liu Jan 18 '11 at 5:23
    
Perhaps we have different versions, but when i compile your example I get the error in my question above. –  Tiago Veloso Jan 18 '11 at 9:02
    
Today I have updated my TeX distribution. I can confirm that this now works for me. –  Tiago Veloso Jan 26 '11 at 21:48
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.