![非连续方程计数器(按方程类型增加)](https://linux22.com/image/327116/%E9%9D%9E%E8%BF%9E%E7%BB%AD%E6%96%B9%E7%A8%8B%E8%AE%A1%E6%95%B0%E5%99%A8%EF%BC%88%E6%8C%89%E6%96%B9%E7%A8%8B%E7%B1%BB%E5%9E%8B%E5%A2%9E%E5%8A%A0%EF%BC%89.png)
我正在尝试使用两个独立的方程计数器,一个用于 TypeA 方程,另一个用于 TypeB 方程。它们不应共享一个计数器,而应从它们所属的类型中选择计数器。
请注意,这与连续部分、小节等不同。我正在使用该amsmath
包。
我想要以下内容(我不关心它是(1.1、1.2、...)还是(1a、1b、...)):
TypeA 1 (Funky Equation)
a = n (1.1)
b = m (1.2)
TypeB 1 (Crazy Equation)
a = n (1.1)
b = m (1.2)
TypeA 2 (Funkier Equation)
a = n (2.1)
b = m (2.2)
TypeB 2 (Crazies Equation)
a = n (2.1)
b = m (2.2)
TypeB 3 (Crazies Equation)
a = n (3.1)
b = m (3.2)
TypeB 4 (Crazies Equation)
a = n (4.1)
b = m (4.2)
TypeA 3 (Crazy Equation)
a = n (3.1)
b = m (3.2)
我的标题中有这个:
\newtheorem{typeagroup}{TypeA}
\newtheorem{typea}[typeagroup]{TypeA}
\counterwithout{equation}{typeagroup}
\newtheorem{typebgroup}{TypeB}
\newtheorem{typeb}[typebgroup]{TypeB}
\counterwithout{equation}{typebgroup}
请注意,只有当 TypeB 存在时,计数器才会递增。这是因为它是\counterwithin{}
上述定义中的最后一个。
以下是我对每种类型的方程使用的代码格式:
\begin{typea}[Funky Equation]
\begin{subequations}
\begin{align}
a = n \\
b = m
\end{align}
\end{subequations}
\end{typea}
\begin{typeb}[Crazy Equation]
\begin{subequations}
\begin{align}
a = n \\
b = m
\end{align}
\end{subequations}
\end{typeb}
我得到以下信息:
TypeA 1 (Funky Equation)
a = n (0.1a)
b = m (0.1b)
TypeB 1 (Crazy Equation)
a = n (1.1a)
b = m (1.1b)
TypeA 2 (Funkier Equation)
a = n (1.1a)
b = m (1.1b)
TypeB 2 (Crazies Equation)
a = n (2.1a)
b = m (2.1b)
TypeB 3 (Crazies Equation)
a = n (3.1a)
b = m (3.1b)
TypeB 2 (Crazies Equation)
a = n (2.1a)
b = m (2.1b)
TypeA 3 (Crazy Equation)
a = n (2.1a)
b = m (2.1b)
答案1
定义新环境:
\documentclass{article}
\usepackage{amsmath}
\newtheorem{typea*}{Type A}
\newtheorem{typeb*}{Type B}
\newenvironment{typea}
{\setcounter{equation}{\value{typea*}}\begin{subequations}\begin{typea*}}
{\end{typea*}\end{subequations}}
\newenvironment{typeb}
{\setcounter{equation}{\value{typeb*}}\begin{subequations}\begin{typeb*}}
{\end{typeb*}\end{subequations}}
\begin{document}
\begin{typea}[Funky Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typea}
\begin{typeb}[Crazy Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typeb}
\begin{typea}[Funky Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typea}
\begin{typeb}[Crazy Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typeb}
\begin{typeb}[Crazy Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typeb}
\begin{typeb}[Crazy Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typeb}
\begin{typea}[Funky Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typea}
\end{document}
如果您还需要与这些无关的“常规”方程数,则可以进行安排。
添加前缀非常简单:
\documentclass{article}
\usepackage{amsmath}
\newtheorem{typea*}{Type A}
\newtheorem{typeb*}{Type B}
\newenvironment{typea}
{\setcounter{equation}{\value{typea*}}%
\renewcommand{\theequation}{A-\arabic{equation}}%
\begin{subequations}%
\begin{typea*}}
{\end{typea*}\end{subequations}}
\newenvironment{typeb}
{\setcounter{equation}{\value{typeb*}}%
\renewcommand{\theequation}{B-\arabic{equation}}%
\begin{subequations}%
\begin{typeb*}}
{\end{typeb*}\end{subequations}}
\begin{document}
\begin{typea}[Funky Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typea}
\begin{typeb}[Crazy Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typeb}
\begin{typea}[Funky Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typea}
\begin{typeb}[Crazy Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typeb}
\begin{typeb}[Crazy Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typeb}
\begin{typeb}[Crazy Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typeb}
\begin{typea}[Funky Equation]
\begin{align}
a = n \\
b = m
\end{align}
\end{typea}
\end{document}
答案2
我不明白你为什么要通过新的定理定义来进行。你可以定义一个新的计数器并将 LaTeX 的方程计数器别名化为它。这是我的宏版本\makeeqcontext
(改编自我以前为自己编写的一些代码):
\makeatletter
\def\makeeqcontext#1#2{%
\edef\tmp@eqcontextcountername{eqcounter#1}%
\expandafter\newcounter{\tmp@eqcontextcountername}%
\expandafter\def\csname #1\endcsname{%
\begingroup%
\expandafter\let\expandafter\c@equation\csname c@eqcounter#1\endcsname%
\renewcommand{\theequation}{#2}%
%
}%
\expandafter\def\csname end#1\endcsname{%
\endgroup%
}
}%
\makeatother
其使用方法如下:
\makeeqcontext{<environment-name>}{<equation-label>}
它定义了一个具有给定名称的新环境,其中方程式具有具有给定标签的单独计数器。这是一个完全可行的例子:
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\makeeqcontext#1#2{%
\edef\tmp@eqcontextcountername{eqcounter#1}%
\expandafter\newcounter{\tmp@eqcontextcountername}%
\expandafter\def\csname #1\endcsname{%
\begingroup%
\expandafter\let\expandafter\c@equation\csname c@eqcounter#1\endcsname%
\renewcommand{\theequation}{#2}%
%
}%
\expandafter\def\csname end#1\endcsname{%
\endgroup%
}
}%
\makeatother
\makeeqcontext{typea}{A-\arabic{equation}}
\begin{document}
% default equation type:
\begin{align}
a = b
\label{a}
\end{align}
\begin{typea} % equation type A:
\begin{align}
c = d
\label{c}
\end{align}
\end{typea}
\begin{typea} % equation type A:
\begin{subequations}
\begin{align}
e &= f \\
g &= h \label{g}
\end{align}
\end{subequations}
\end{typea}
Reference~\eqref{a}, \eqref{c} and~\eqref{g}.
\end{document}