开发者

How can I attach a LaTeX marker to an arbitrary place in text?

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?


This is the solution:

\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.

Posted by Will at https://tex.stackexchange.com/questions/4021/how-to-set-a-marker-counter-label-to-an-arbitrary-piece-of-text


If you want to have a label, consider the following (from here);

  • \label{marker} You give the object you want to reference a marker, you can see it like a name.

  • \ref{marker} You can reference the object you have marked before. This prints the number that was assigned to the object.

  • \pageref{marker} It will print the number of the page where the object is.

Normally, if you reference to a label, LaTeX prints out the section, subsection, etc. But if you want to specify the exact place in text, you can use pageref. So with pageref you can exactly print out the page number of the "marker".

This is - as far as i know - the most exact possibility to tell the reader where in text a "marker" was, i.e. it is - as far as i know - impossible to tell LaTeX to print the exact line number or so.


You can use \label anywhere, including in the body of the text, but the thing labelled will be (roughly) the 'current labellable thing', that is the last \*section, or the current equation or table.

If you want to label something else (what is it you're after?) then you'll have to roll your own (not trivial), and have something which, if I recall correctly, sets \@currentlabel.

Edited, to add:

\begin{document}
\section{Hello}
Here is some text
\label{l1}
More text.
\newpage
Further text, on page 2
\label{l2}

This is section~\ref{l1} on page~\pageref{l1}.
And section~\ref{l2} on page~\pageref{l2}.
\end{document}

In both cases, the \ref refers to section 1, though the \pageref refers to pages 1 and 2 respectively. In both cases, the 'thing being labelled' is the section, and the text that goes in the label, and which appears in the \ref, is the section number.

So if you want to refer to an 'arbitrary place in the text', you have to ask yourself 'what is the text that would be produced by the \ref?'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜