如何将 LaTeX 标记附加到文本中的任意位置?

发布于 2024-09-25 13:24:51 字数 452 浏览 1 评论 0原文

是否可以将标记仅附加到文本中的某个位置,而不是部分、子部分等?

这就是我想要实现的目标:

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

我想要得到这样的东西:

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

有意义吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

§对你不离不弃 2024-10-02 13:24:51

这就是解决方案:

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

由 Will 在 https://tex.stackexchange.com/questions/4021/how-to-set-a-marker-counter-label-to-an-任意-piece-of-text

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

离不开的别离 2024-10-02 13:24:51

如果您想要一个标签,请考虑以下内容(来自此处);

  • \label{marker} 你给你想要引用的对象一个标记,你可以看到它就像一个名字。

  • \ref{marker} 您可以引用之前标记的对象。这将打印分配给该对象的编号。

  • \pageref{marker} 它将打印该对象所在的页码。

通常,如果您引用标签,LaTeX 会打印出节、小节等。但如果您想指定文本中的确切位置,则可以使用 pageref 。因此,使用 pageref 您可以准确地打印出“标记”的页码。

据我所知,这是告诉读者文本中“标记”在哪里的最准确的可能性,即据我所知,不可能告诉 LaTeX 打印确切的行号左右。

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.

滥情哥ㄟ 2024-10-02 13:24:51

您可以在任何地方使用 \label,包括在文本正文中,但标记的内容将(大致)是“当前可标记的内容”,即最后一个 \*section,或当前方程或表格。

如果你想标记其他东西(你想要什么?),那么你必须自己推出(不是微不足道的),并且有一些东西,如果我没记错的话,设置 \@currentlabel.

已编辑,添加:

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

在这两种情况下,\ref 均指第 1 节,尽管 \pageref 分别指第 1 页和第 2 页。在这两种情况下,“被标记的东西”都是节,标签中出现的文本以及出现在 \ref 中的文本是节号。

因此,如果您想引用“文本中的任意位置”,您必须问自己“\ref 将生成什么文本?”

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?'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文