如何在LaTeX中识别两个计数器?

发布于 2024-09-08 19:39:50 字数 230 浏览 1 评论 0原文

在某个文档中,我想让两个计数器“定理”和“分段”成为同一个东西。有什么想法吗?

编辑:由于数学部分可能会令人困惑,因此我将问题改述如下,没有任何此类引用。

我使用某个计数器“mycounter”来计数某些内容,并且该计数器是在某个包中预定义的。当该小节上升时,我希望“mycounter”上升。反之亦然。当重置小节时,我希望重置“mycounter”。

这就是我希望通过识别两个计数器来实现的目的。

In a certain document, I want to make the two counters "theorem" and "subsection" to be one and the same thing. Any ideas?

Edit: Since the math parts are potentially confusing, I rephrase the question as follows without any such references.

I use a certain counter "mycounter" for counting something, and this counter is predefined in a certain package. When the subsection goes up, I want "mycounter" to go up. And vice-versa. When subsection is reset, I want "mycounter" to be reset.

This is what I hope to achieve by identifying the two counters.

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

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

发布评论

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

评论(4

千寻… 2024-09-15 19:39:50

赫伯特·西斯特就快到了。

\newtheorem{theorem}{Theorem}[subsection] 会对小节中的定理进行编号(即,第 1.2 节中的定理将是 1.2.1、1.2.2 等) 。相反, \newtheorem{theorem}[subsection]{Theorem} 似乎可以满足OP的要求。 (比如说)1.5 节之后是定理 1.6,定理 1.6 之后是 1.7 节。定理的格式与章节不同。

另一种方法是这样做,

\def\theorem#1{\begingroup
  \let\tempsubsection\thesubsection
  \def\thesubsection{Thm.~\tempsubsection}%
  \subsection{#1}%
  \endgroup
}

这稍微更“自制”,但使定理具有与 \subsection 完全相同的布局,这可能是也可能不是所需要的。

Herbert Sizt is almost there.

\newtheorem{theorem}{Theorem}[subsection] would number theorems within subsections (ie, the theorems within Section 1.2 would be 1.2.1, 1.2.2, etc). Instead \newtheorem{theorem}[subsection]{Theorem} appears to do what the OP requires. Section 1.5 (say) would be followed by theorem 1.6, which would be followed by section 1.7. The theorem is formatted differently from sections.

An alternative way is to do

\def\theorem#1{\begingroup
  \let\tempsubsection\thesubsection
  \def\thesubsection{Thm.~\tempsubsection}%
  \subsection{#1}%
  \endgroup
}

That's slightly more 'home-made', but makes the theorems have exactly the same layout as \subsection, which may or may not be what's required.

撕心裂肺的伤痛 2024-09-15 19:39:50

我认为一种方法是创建一个用户定义的计数器(例如“mycounter”),然后修改部分和定理命令以(1)使用该计数器而不是内置的 \thesection 或 \thetheorem (2) 每次使用时自动增加共享的用户定义计数器。

我相信 titlesec 或 secsty 包将允许您重新定义部分样式以使用和增加用户定义的计数器。不确定定理,但我假设有一些包可以让您修改这些定理。

这只是一种方法。不确定是否有更干净或更直接的东西。对我来说,这似乎是一个非常干净和简单的方法,尽管我必须查看有关如何使用用户定义计数器的文档,不确定它在网络上的位置,我知道 Kopka 的 Latex 指南中有很多信息。

编辑:抱歉,也许上面的内容超出了需要的范围,我不使用 LaTeX 做数学,对定理命令/环境一无所知。您是否可以定义一个自动使用节编号的定理环境?我想知道在查看此页面后: http://www. maths.tcd.ie/~dwilkins/LaTeXPrimer/Theorems.html

EDIT_2:查看 Kopka 的指南后,是的,看起来您确实可以使用 \newtheorem 命令来创建使用节计数器的定理环境。例如,“\newtheorem{theorem}{Theorem}[subsection]”将创建使用 subsection 计数器的新“theorem”环境。不确定它是否可以散布在小节中,并在每个新的“节”处正确递增和重置,但我希望这就是想法。

I think one way to do it would be to create a user-defined counter (say, 'mycounter') and then modify the section and theorems commands to both (1) use that counter instead of the built-ins \thesection or \thetheorem and (2) to automatically increment your shared user-defined counter each time it's used.

I believe the titlesec or secsty packages would allow you to redefine section styles to use and increment your user-defined counter. Not sure about theorems, but I assume there's some package that would let you modify those too.

This is just one approach. Not sure if there's something that would be cleaner or more straightforward. This seems a pretty clean and straightforward method to me, although I would have to review docs on how to use user-defined counters, not sure where it is on the web, I know there's plenty of info in Kopka's Guide to Latex.

EDIT: Sorry, maybe the above is way more than is needed, I don't do math with LaTeX and know nothing about Theorem command/environment. Could it be that you can define a theorem environment that automatically uses section numbering? I'm wondering that after looking at this page: http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/Theorems.html

EDIT_2: After looking at Kopka's Guide, yes, it does look like you can use \newtheorem command to create a theorem environment that uses the section counter. E.g., '\newtheorem{theorem}{Theorem}[subsection]' would create new 'theorem' environment that uses the subsection counter. Not sure if it then can be interspersed with subsections and have both increment properly and reset at each new 'section', but I expect that's the idea.

顾挽 2024-09-15 19:39:50

这并不明显,但这最初似乎是另一个问题的几乎重复;但这不是完全相同的问题。您具体要求的内容可能会以类似的黑客方式得到解决,但尚不完全清楚您要求的是什么 - 您的问题是否有更多“元”版本?

您的想法是想在每个定理的一个小节中声明它,并因此想通过该编号来引用它吗?在这种情况下,...see Theorem~\ref{sec:foo} 可能会让您至少完成一半,而无需任何特殊的定制。

It's not obvious, but this initially appears to be a near-duplicate of another question; but it's not quite the same problem. What you're specifically asking for could potentially be addressed in a similar hacky way, but it's not completely clear what you're asking for -- is there a more 'meta' version of your question?

Is the idea that you want to declare each theorem in a subsection of its own, and so want to refer to it by that number? In which case, ...see Theorem~\ref{sec:foo} might get you at least half-way there without any special customisation.

你列表最软的妹 2024-09-15 19:39:50

这是诺曼·格雷给出的答案的一个例子,当我运行它时,它看起来很棒。非常好的诺曼,谢谢。 (您可以互换 \newtheorem 行上的 [subsection] 和 {Theorem} 元素,看看它如何影响事物。):

\documentclass{article}

\newtheorem{theorem}[subsection]{Theorem}

\begin{document}
\section{My Section}
\subsection{A subsection}

\begin{theorem}adfadfadf
\end{theorem}

\subsection{A subsection}

\begin{theorem}adfadfadf
\end{theorem}
\begin{theorem}adfadfadf
\end{theorem}

\begin{theorem}
\emph{(Lagrange's Theorem)}
\label{Lagrange}
Let $G$ be a finite group, and let $H$ be a subgroup
of $G$.  Then the order of $H$ divides the order of $G$.
\end{theorem}

\end{document}

This is an example of the answer that Norman Gray gave, which looks great to me when I run it. Very nice Norman, thanks. (You can interchange the [subsection] and {Theorem} elements on the \newtheorem line to see how it affects things.) :

\documentclass{article}

\newtheorem{theorem}[subsection]{Theorem}

\begin{document}
\section{My Section}
\subsection{A subsection}

\begin{theorem}adfadfadf
\end{theorem}

\subsection{A subsection}

\begin{theorem}adfadfadf
\end{theorem}
\begin{theorem}adfadfadf
\end{theorem}

\begin{theorem}
\emph{(Lagrange's Theorem)}
\label{Lagrange}
Let $G$ be a finite group, and let $H$ be a subgroup
of $G$.  Then the order of $H$ divides the order of $G$.
\end{theorem}

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