# Defining a custom cross referencing style

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?

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.

-

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}

-
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