分组子方程编号的划分

分组子方程编号的划分

我正在尝试使用以下答案对子群中的子方程环境中的方程进行编号(类似于示例), 和问题,但我无法得到结果!

\documentclass{article}
\usepackage{amsmath}
\newcommand\StepSubequations{
  \stepcounter{parentequation}
   \stepcounter{equation}
    \gdef\theparentequation{\arabic{parentequation}\Alph{equation}}
  \setcounter{equation}{0}
  \setcounter{parentequation}{1}
}
\begin{document}
    \begin{subequations}
        \begin{align}
            1   &=  1\\
            2   &=  2\\
            \StepSubequations
            3   &=  3\\% from here a new equation number
            4   &=  4\\
            5   &=  5\\
            6   &=  6\\
            \StepSubequations
            7   &=  7\\
            8   &=  8\\
            \StepSubequations
            9   &=  9\\
        \end{align}
      \end{subequations}

\end{document}

预期成绩:

(1aA)

(1aB)

(1bA)

(1bB)

(1bC)

(1bD)

(1cA)

(1CB)

(1天)

答案1

我不确定您到底想做什么,也不知道在subequations您不使用的环境中会发生什么\StepSubequations......也许创建一个新的环境(作为原始环境的副本)来按照您想要的方式处理事情是个好主意,这样您就可以保留原始行为。

无论如何,像这样的事情可以作为起点(但它不会抑制单个“A”,因为这需要向前看):

\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}
\newcounter{equationgroup}
\makeatletter
\patchcmd\subequations
    {\def\theequation{\theparentequation\alph{equation}}}
    {\def\theequation{\theparentequation\Alph{equation}}\ifmeasuring@\else\setcounter{equationgroup}{1}\fi}
    {}{}
\makeatother
\newcommand\StepSubequations{
    \stepcounter{equationgroup}
    \stepcounter{equation}
    \gdef\theparentequation{\arabic{parentequation}\alph{equationgroup}}
    \setcounter{equation}{0}
}

\begin{document}
    \begin{subequations}
        \begin{align}
            1   &=  1\\
            2   &=  2\\
            \StepSubequations
            3   &=  3\\% from here a new equation number
            4   &=  4\\
            5   &=  5\\
            6   &=  6\\
            \StepSubequations
            7   &=  7\\
            8   &=  8\\
            \StepSubequations
            9   &=  9
        \end{align}
    \end{subequations}

    \begin{subequations}
        \begin{align}
            1   &=  1\\
            2   &=  2\\
            \StepSubequations
            3   &=  3\\% from here a new equation number
            4   &=  4\\
            5   &=  5\\
            6   &=  6\\
            \StepSubequations
            7   &=  7\\
            8   &=  8\\
            \StepSubequations
            9   &=  9
        \end{align}
    \end{subequations}
\end{document}

在此处输入图片描述


您还可以将重新定义放入随后需要执行的命令中(这将使您能够subequations更轻松地在环境的原始行为和调整后的行为之间进行切换)。因此,可能是这样的:

\documentclass{article}
\usepackage{amsmath}
\newcounter{subequationsgroup}
\makeatletter
\AddToHook{env/subequations/after}{%
    \stepcounter{parentequation}%
    \gdef\theequation{\theparentequation}%
}
\newcommand{\InitializeSubequationsGroups}{%
    \ifmeasuring@\else%
        \setcounter{subequationsgroup}{\value{equation}}%
    \fi%
}
\newcommand{\StepSubequationsGroup}{%
    \ifmeasuring@\else%
        \stepcounter{subequationsgroup}%
        \setcounter{equation}{0}%
        \gdef\theequation{\theparentequation\alph{subequationsgroup}\Alph{equation}}%
    \fi%
}
\newcommand{\StepSubequationsSingle}{%
    \ifmeasuring@\else%
        \stepcounter{subequationsgroup}%
        \setcounter{equation}{0}%
        \gdef\theequation{\theparentequation\alph{subequationsgroup}}%
    \fi%
}
\makeatother

\begin{document}
    \begin{subequations}
        \begin{align}
            1   &=  1\\
            2   &=  2
        \end{align}
    \end{subequations}

    \begin{subequations}
        \begin{align}
            \InitializeSubequationsGroups
            \StepSubequationsGroup
            1   &=  1\\
            2   &=  2\\
            \StepSubequationsGroup
            3   &=  3\\% from here a new equation number
            4   &=  4\\
            5   &=  5\\
            \StepSubequationsSingle
            6   &=  6\\
            \StepSubequationsGroup
            7   &=  7\\
            8   &=  8\\
            1   &=  1\\
            2   &=  2
        \end{align}
    \end{subequations}

    \begin{subequations}
        \begin{align}
            1   &=  1\\
            2   &=  2
        \end{align}
    \end{subequations}
\end{document}

在此处输入图片描述


align我最后一次尝试,它应该允许您在环境中放置多个命令subequations。您只需要注意\EndSubequationsGroup如果命令位于subequations环境中的最后,则将其放置在何处:

\documentclass{article}
\usepackage{amsmath}
\newcounter{subequationsgroup}
\makeatletter
\AddToHook{env/subequations/before}{%
    \gdef\theequation{\arabic{equation}}%
}
\newcommand{\BeginSubequationsGroup}{%
    \ifmeasuring@\else%
        \setcounter{subequationsgroup}{\value{equation}}%
        \setcounter{equation}{0}%
        \stepcounter{subequationsgroup}%
        \gdef\theequation{\theparentequation\alph{subequationsgroup}\Alph{equation}}%
    \fi%
}
\newcommand{\EndSubequationsGroup}{%
    \ifmeasuring@\else%
        \setcounter{equation}{\value{subequationsgroup}}%
        \gdef\theequation{\theparentequation\alph{equation}}%
    \fi%
}
\makeatother

\begin{document}
    \begin{subequations}
        \begin{align}
            1   &=  1\\
            2   &=  2
        \end{align}
    \end{subequations}

    \begin{subequations}
        \begin{align}
            \BeginSubequationsGroup
            1   &=  1\\
            2   &=  2\\
            \EndSubequationsGroup
            3   &=  3\\
            \BeginSubequationsGroup
            4   &=  4\\
            5   &=  5\\
            \EndSubequationsGroup
            6   &=  6
        \end{align}
    \end{subequations}

    \begin{subequations}
        \begin{align}
            1   &=  1\\
            2   &=  2
        \end{align}
        
        \begin{align}
            \BeginSubequationsGroup
            1   &=  1\\
            2   &=  2
            %\EndSubequationsGroup
        \end{align}
    \end{subequations}

    \begin{subequations}
        \begin{align}
            1   &=  1\\
            \BeginSubequationsGroup
            2   &=  2\\
            3   &=  3\\
            \EndSubequationsGroup
            4   &=  4\\
            5   &=  5\\
            \BeginSubequationsGroup
            6   &=  6\\
            7   &=  7\\
            8   &=  8
        \end{align}
        
        \begin{align}
            \EndSubequationsGroup
            1   &=  1\\
            2   &=  2
        \end{align}
    \end{subequations}
\end{document}

在此处输入图片描述

相关内容