如何在同一文档中创建两组对齐方程?

如何在同一文档中创建两组对齐方程?

这个问题类似于上一个问题关于如何在同一文档中创建两个系列的编号方程。但是,建议的解决方案对我的问题不起作用,因为它在环境中将计数器增加一次。相反,我需要一个适用于环境的解决方案align。那么,如何使用对齐环境处理两个系列的方程编号?

例如,我需要环境alignAalignB允许我写入:

\begin{alignA}
  x &= 2*y \\
    &= 3*z
\end{alignA}

\begin{alignB}
  u &= 4*v \\
    &= 5*w
\end{alignB}

输出方程编号 A1、A2、B1 和 B2。

答案1

以下是通过环境声明提供的更结构化的选项

\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}

\makeatletter
\newcounter{qrr@oldeq}
\newcounter{qrr@oldsubeq}
\newcounter{qrr@realeq}

\newcounter{Bqrr@oldeq}
\newcounter{Bqrr@oldsubeq}
\newcounter{Bqrr@realeq}


\newenvironment{AlignA*}{% Consecutive subequations A
\setcounter{qrr@realeq}{\value{equation}}%
\let\theparentequation\theequation%
\patchcmd{\theparentequation}{equation}{parentequation}{}{}%
\setcounter{parentequation}{\numexpr\value{qrr@oldeq}-1}%
\setcounter{equation}{\value{qrr@oldsubeq}}%
\def\theequation{A-\arabic{equation}}%
\refstepcounter{parentequation}%
\ignorespaces
}{%
\setcounter{qrr@oldeq}{\value{parentequation}}%
\setcounter{qrr@oldsubeq}{\value{equation}}%
\setcounter{equation}{\value{qrr@realeq}}%
\ignorespacesafterend
}

\newenvironment{AlignA}{% Non consecutive subequations A
\refstepcounter{equation}%
\protected@edef\theparentequation{\theequation}%
\setcounter{parentequation}{\value{equation}}%
\setcounter{equation}{0}%
\def\theequation{A-\arabic{equation}}%
\ignorespaces
}{%
\setcounter{qrr@oldeq}{\value{parentequation}}%
\setcounter{qrr@oldsubeq}{\value{equation}}%
\setcounter{equation}{\value{parentequation}}%
\ignorespacesafterend
}

\newenvironment{AlignB}{% Non consecutive subequations B
\refstepcounter{equation}%
\protected@edef\theparentequation{\theequation}%
\setcounter{parentequation}{\value{equation}}%
\setcounter{equation}{0}%
\def\theequation{B-\arabic{equation}}%
\ignorespaces
}{%
\setcounter{Bqrr@oldeq}{\value{parentequation}}%
\setcounter{Bqrr@oldsubeq}{\value{equation}}%
\setcounter{equation}{\value{parentequation}}%
\ignorespacesafterend
}

\newenvironment{AlignB*}{% Consecutive subequations B
\setcounter{Bqrr@realeq}{\value{equation}}%
\let\theparentequation\theequation%
\patchcmd{\theparentequation}{equation}{parentequation}{}{}%
\setcounter{parentequation}{\numexpr\value{Bqrr@oldeq}-1}%
\setcounter{equation}{\value{Bqrr@oldsubeq}}%
\def\theequation{B-\arabic{equation}}%
\refstepcounter{parentequation}%
\ignorespaces
}{%
\setcounter{Bqrr@oldeq}{\value{parentequation}}%
\setcounter{Bqrr@oldsubeq}{\value{equation}}%
\setcounter{equation}{\value{qrr@realeq}}%
\ignorespacesafterend
}

\makeatother

\begin{document}


The AlignA environment goes from A-1 to A-n and if you use it again eq. counter resets
\begin{AlignA}
\begin{align}
\alpha\\
\beta\\
\gamma\\
\delta
\end{align}
\end{AlignA}
%\thesubA
The AlignB environment goes from B-1 to B-n and if you use it again eq. counter resets
\begin{AlignB}
\begin{align}
\alpha\\
\beta\\
\gamma
\end{align}
\end{AlignB}
The AlignA* environment goes from A-n to A-n+m and if you use it again eq. counter stay
\begin{AlignA*}
\begin{align}
\alpha\\
\beta\\
\gamma
\end{align}
\end{AlignA*}
 The AlignB* environment goes from B-n to B-n+m and if you use it again eq. counter stay
\begin{AlignB*}
\begin{align}
\alpha\\
\beta\\
\gamma
\end{align}
\end{AlignB*}
A normal Equation
\begin{equation}
\mbox{other equation}
\end{equation}


\end{document}

在此处输入图片描述

答案2

据我了解,您首先需要声明环境“AlingA”和“AlingB”,并使用 \renewcomand 对它们进行反击

或者试试这个(加载 ams 数学包)

\begin{subequations}
\renewcommand{\theequation}{A-\arabic{equation}}
\begin{equation}
A=y
\end{equation}
\begin{equation}
y=2 
\end{equation}
\end{subequations}
\setcounter{equation}{0} % reset to 0 equation counter
\begin{subequations}
\renewcommand{\theequation}{B-\arabic{equation}}
\begin{equation}
B=2y
\end{equation}
\begin{equation}
y=2 
\end{equation}
\end{subequations}

相关内容