3

I want to reference a section with cleveref like in the following example:

\section{Foobar}
\label{sec:foobar}

See \cref{sec:foobar}.

The output of this is:

See section 1.

But what I would like is this:

See section 1 Foobar.

I understand that there is no command by default, that produces this output.

So I tried to build my own command like suggested for the hyperref package in this question. However, I could not find an equivalent command to hyperref's \nameref in cleveref's documentation.

Is it possible to create a new command, that produces my desired output?

  • 1
    You can just load hyperref and use its \nameref command on top of cleveref. – Andrew Swann Sep 11 '13 at 13:20
  • @sfat What about Andrew's suggestion? Is it working for you? – Ludovic C. Sep 15 '13 at 22:54
  • Yes, it is. Quite comfortabily actually, as I've been using hyperref anyway. I think this could be posted as an answer to the question. – sfat Sep 16 '13 at 6:28
6

According to @AndrewSwann's suggestion, I created a command, that makes use of both cleveref's \Cref and hyperref's \nameref:

\newcommand*{\fullref}[1]{\hyperref[{#1}]{\Cref*{#1} \nameref*{#1}}}

The benefit compared to the solution in this question, which only uses hyperref, is that the use of \Cref allows for capitalized reference names.

Both \Cref and \nameref create a single link. Encapsulating them in \hyperref merges them to a single link.

  • With regard to the query you posted originally, what is the instruction \hyperref[{#1}] inside the \fullref macro supposed to achieve? – Mico Oct 19 '13 at 9:21
  • I have edited my answer to clarify \hyperref's intent. – sfat Oct 19 '13 at 9:38
  • Thanks for explaining what the \hyperref[]{} instruction does. – Mico Oct 19 '13 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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