How can we give a name to a label so that when we do the cross-reference, instead of displaying the number of the section, we have the name of the label?

For example,

\underline{homogeneity in preferences(HP)\phantomsection\label{hyp3}}

When I use \ref{hyp3} I would like the shown reference text to be HP and not e.g. 5.1 that is the number of the section.

Can someone help me?

  • Take a look at this: tex.stackexchange.com/a/70153/105976
    – sporc
    Jul 2, 2018 at 8:32
  • 2
    (1) welcome, (2) please provide a full minimal example so we can see what you are doing? Why are you making headlines marked by underline? Nobody does that anymore. LaTeX has several options when we are dealing with say \section then we can get the title associated with a \label, see for example the nameref package (it is build into the memoir class under the name \titleref)
    – daleif
    Jul 2, 2018 at 8:32
  • You can also look at the packages showkeys or showlabels
    – StefanH
    Jul 2, 2018 at 8:36
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Aug 17, 2018 at 9:43

2 Answers 2


Taking the excellent answer by egreg (Labeling a text and referencing it later) and modifying it to take an additional optional argument I could come up with the solution below. It creates a new command \labeltext that can be referenced to. It takes two parameters and one optional parameter:

\labeltext[optional short ref]{the labeled text}{label name}

If you want to, you can set the markup or highlighting of the label and (optionally) the reference, too. I set it to \emph rather than \underline as underlining looks bad to me and is considered bad practice.




    \csname phantomsection\endcsname% in case hyperref is used
    \def\labelmarkup{\emph}% How to markup the label itself
    %\def\refmarkup{\labelmarkup}% How to markup the reference
    \labelmarkup{#2}% visible printed text.

Some text. This is text. \labeltext{This is the labeled text with lab1}{lab1}. More text.\\
\labeltext[shorter text 2]{Long labeled text 2}{lab2}\\
\labeltext[HP]{homogeneity in preferences (HP)}{hyp3}

This reference shows lab1: \ref{lab1}.\\
This reference shows lab2: \ref{lab2}.\\
Reference to \ref{hyp3}.

It seems like you’re using the ref-mechanism for something like acronyms so you might want consider using the glossaries package instead. That'll give you also the opportunity to automatically create a list of uses acronyms/abbreviations.

Here’s an example how to use the package to print the acronym: first time the full text and from there one only the abbreviation/acronym.




\newacronym{hp}{HP}{homogeneity in preferences}


This is the first sentence about \gls{hp}.

Somewhere later in the doc it is used again as \gls{hp}.


enter image description here

And by the way: Please do not use underlining!

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.