16

Is it possible to attach a marker to just a place in text, not to section, sub-section, etc.?

This is what I'm trying to achieve:

\begin{document}
Alex (see~\ref{alex}) is a boy, 
Jessica (see~\ref{jessica}) is a girl.
[...]
\label{alex}\ref{alex}: Alex Johnson: 4 y.o.
\label{jessica}\ref{jessica}: Jessica D.: 5 y.o.
\end{document}

I want to get something like this:

Alex (see 1) is a boy, 
Jessica (see 2) is a girl.
[...]
1: Alex Johnson: 4 y.o.
2: Jessica D.: 5 y.o.

Makes sense?

2
  • The specific example could be done with an enumerated list, is there a reason why you don't want to do that? Oct 12, 2010 at 11:28
  • @Andrew This is just an example. Correct solution is proposed by Will Robertson below.
    – yegor256
    Oct 12, 2010 at 11:30

2 Answers 2

22

You can only \ref-er to a \label that has been attached to a counter using \refstepcounter. For example:

\newcounter{foo}
...
Alex (see~\ref{alex}) is a boy, 
Jessica (see~\ref{jessica}) is a girl.
[...]
\refstepcounter{foo}\thefoo\label{alex}: Alex Johnson: 4 y.o.
\refstepcounter{foo}\thefoo\label{jessica}: Jessica D.: 5 y.o.

Internally, this is the way that all labelling and referencing is done with sections, figures, and so on.

0
11

For who ever might be interested, adapted from Will Robertson's solution:

Problem: You wish to have an enumeration (e.g. an enumeration of 'hypotheses' in a research proposal) throughout the text, and reference that enumeration in the text.

Solution: Define

\newcounter{hypothesiscounter}
\newcommand*{\hyplabel}[1]{H\refstepcounter{hypothesiscounter}\thehypothesiscounter\label{#1}}
\newcommand*{\hypref}[1]{H\ref{#1}}

and use as:

This shall be hypothesis \hyplabel{HYP:CRAZY_HYPOTH}. I shall explain hypothesis \hypref{HYP:CRAZY_HYPOTH} below.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .