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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, I have :

\section {first section}

then I want to refer to the first section, I use it as below:

Please look at `\nameref{first}` for details. 

I will get:

Please look at first section for details.

But if I only want this (without section, only partial part of the reference):

Please look at first for details.

How should I do to get it?

I guess a better example would be:

\section{data.h File Description} 
Details are given in \nameref{datah}.  

What I really want is:

Details are given in data.h.

But I get:

Details are given in data.h File Description.

I hope this example is clear enought. Is there any way to do this?

share|improve this question

migrated from stackoverflow.com Sep 22 '12 at 17:33

This question came from our site for professional and enthusiast programmers.

Do you always use \section{first section} ... \section{second section} ... \section{some section}, or does it differ sometimes? Since the sections are numbered and the output is 1 First section, you should consider just writing \section{First} which will output 1 First and yield the appropriate \nameref you're after. – Werner Sep 21 '12 at 17:59
Thanks for your reply. Here it is only an example, not the real contents. – user1558064 Sep 21 '12 at 18:06
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Sep 22 '12 at 17:56
\nameref is not a standard LaTeX command. Please provide a minal example. – Marc van Dongen Sep 22 '12 at 18:13

Since the required return from a \nameref might be anywhere inside the title of a \section, you can use \labelname{<stuff>} as defined below to update the reference text returned:

enter image description here

\usepackage{nameref}% http://ctan.org/pkg/nameref
\newcommand{\labelname}[1]{% \labelname{<stuff>}
\section{\texttt{data.h} File Description}
\labelname{\texttt{data.h}}\label{sec:datah}% Overwrite title name/reference
Also see \nameref{sec:dataj}.

\section{File Description for \texttt{data.j}}
\label{sec:dataj}% Keep regular title reference
Details are given in \nameref{sec:datah}.

nameref stores the name of the previous title in \@currentlabelname, which is overwritten using \labelname.

This is also compatible with hyperref.

share|improve this answer
The important thing is that \labelname comes before \label. The solution also does not change the label in the TOC. :thumbsup: – koppor Nov 14 '13 at 9:50

Your Answer


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