通过添加字母自动用父编号对子方程进行编号

通过添加字母自动用父编号对子方程进行编号

在下面的 MWE 中,我需要用父编号对一些子方程式进行编号,但会自动添加字母。

\documentclass[]{article}
\begin{document}

The parentalequation
\begin{equation}\label{First}
    x^2 - 1 = 0
\end{equation}

Same equation in different place of text
\begin{equation}\label{Second}
 (x - 1)( x + 1) = 0 % need to be numerated as main equation labeled by First but with adding letter, e. g. like 1a
\end{equation}
\end{document}

答案1

根据我在这里的回答:

https://tex.stackexchange.com/a/377481/120578

代码可以更改如下:

\documentclass[10pt]{article}
\usepackage{amsmath}
\makeatletter
\newcommand*\ifcounter[1]{%
  \ifcsname c@#1\endcsname%
    \expandafter\@firstoftwo%
  \else%
    \expandafter\@secondoftwo%
  \fi%
}%
\makeatother


\makeatletter
\newcommand\EqFamTag[2][roman]{%
\ifcounter{#2}{%
\expandafter\addtocounter{#2}{1}%
\xdef\temp{\csname #2 Eq\endcsname \csname\csname #2 Default\endcsname\endcsname{#2}}%
\global\expandafter\let\csname #2\arabic{#2}\endcsname\temp%
\tag{\temp}%
}{%
\global\expandafter\newcounter{#2}%
\xdef\temp{\theequation}%
\xdef\eqonfamily{\theequation}%
\global\expandafter\let\csname #2 Eq\endcsname\eqonfamily%
\global\expandafter\let\csname #2\endcsname\temp%
\xdef\kind{#1}%
\global\expandafter\let\csname #2 Default\endcsname\kind%
\tag{\temp}%
\expandafter\addtocounter{equation}{1}%
}%
}%
\makeatother

\makeatletter
\def\refEq#1{(\csname #1\endcsname)}
\makeatother

\begin{document}
The parentalequation

\begin{equation}
x^2-1=0\EqFamTag[alph]{Fam}
\end{equation}

Same equation in different place of text

\begin{equation}
 (x - 1)( x + 1) = 0\EqFamTag{Fam}% need to be numerated as main equation labeled by First but with adding letter, e. g. like 1a
\end{equation}

The (\csname Fam\endcsname) is the same equation as the (\csname Fam1\endcsname)

we can also refer to it like \refEq{Fam} or \refEq{Fam1}

Other equation here:
\begin{equation}
   F(x)=3\cdot x-1
\end{equation}


\end{document}

结果是:

在此处输入图片描述

答案2

我的解决方案是使用\tag{on parent equation.subcounter}下面的代码:

\def\parent#1{\label{#1}
    \newcounter{#1}
    \setcounter{#1}{0}
    }

    \def\child#1{
    \stepcounter{#1}
    \tag{\ref{#1}\alph{#1}}
    }

平均能量损失

\documentclass[]{article}
\usepackage{amsmath}
%--------------------------------------------
\def\parent#1{\label{#1}
\newcounter{#1}
\setcounter{#1}{0}
}

\def\child#1{
\stepcounter{#1}
\tag{\ref{#1}\alph{#1}}
}
%-------------------------------------------
\begin{document}


The parental equation
\begin{equation}\parent{First}
    x^2 - 1 = 0
\end{equation}

Same equation in different place of text
\begin{equation}\label{first}\child{First}
 (x - 1)( x + 1) = 0 % need to be numerated as main equation labeled by First but with adding letter, e. g. like 1a
\end{equation}

Here~\eqref{first}

Same equation in different place of text
\begin{equation}\label{third}\child{First}
 (x - 1)( x + 1) = 0 % need to be numerated as main equation labeled by First but with adding letter, e. g. like 1a
\end{equation}

The parental equation
\begin{equation}\parent{Second}
    x^2 - 1 = 0
\end{equation}

Same equation in different place of text
\begin{equation}\label{anotherfirst}\child{Second}
 (x - 1)( x + 1) = 0 % need to be numerated as main equation labeled by First but with adding letter, e. g. like 1a
\end{equation}

Here~\eqref{anotherfirst}

Same equation in different place of text
\begin{equation}\label{anotherthird}\child{Second}
 (x - 1)( x + 1) = 0 % need to be numerated as main equation labeled by First but with adding letter, e. g. like 1a
\end{equation}

\end{document}

在此处输入图片描述

相关内容