我需要自定义方程编号,如下所示:
Some text ...
a+b (5)
3+2 (5')
... some more text....
c+d (6)
这个想法是 (5') 是 (5) 的一个例子。我想过使用子方程,但我不知道如何自定义内部编号,因为它会生成 5a 和 5b,或 5.i、5.ii 等……如果我改用 \tag{},我不确定如何获取前一个方程编号(示例中为 5)。
答案1
您可以定义一个\eqorn
命令。如果您使用,\eqorn['']
您将获得两个素数;可以在可选参数中指定任何数学符号。
\documentclass{article}
\usepackage{amsmath}
\newcommand{\eqorn}[1][']{\tag{\theequation\ensuremath{#1}}}
\begin{document}
Some text ...
\begin{gather}% or align or whatnot
a+b \label{main} \\
3+2 \eqorn \label{secondary}
\end{gather}
... some more text....
\begin{equation}
c+d
\end{equation}
with references to \eqref{main} and \eqref{secondary}.
\end{document}
答案2
这里有一种方法,使用expl3
来\prg_replicate:nn
生成 的n
副本以'
对 中的方程进行编号,subequations
并etoolbox
使用\patchcmd
将其插入到subequations
环境中。
\documentclass{article}
\usepackage{amsmath}
\usepackage{expl3}
% Creating a command to print a number of apostrophes
\ExplSyntaxOn
\cs_new:Npn \apost #1
{ \__andy_apost:cn { c@ #1 } }
\cs_new:Npn \__andy_apost:Nn #1
{
\ensuremath {
\prg_replicate:nn { #1 - 1 } { {'} }
}
}
\cs_generate_variant:Nn \__andy_apost:Nn { c }
\ExplSyntaxOff
% Patching-in that command in \subequations
\usepackage{etoolbox}
\patchcmd\subequations
{\def\theequation{\theparentequation\alph{equation}}}
{\def\theequation{\theparentequation\apost{equation}}}
{}{\FAIL}
\begin{document}
\begin{subequations}
\begin{equation}
a+b
\end{equation}
\begin{equation}
3+2
\end{equation}
\begin{equation}
5
\end{equation}
\end{subequations}
\end{document}
答案3
另一种方法是修改答案这里:
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand*\ifcounter[1]{%
\ifcsname c@#1\endcsname%
\expandafter\@firstoftwo%
\else%
\expandafter\@secondoftwo%
\fi%
}%
\makeatother
\newcommand\EqFamTag[2][roman]{%
\ifcounter{#2}{%
\expandafter\addtocounter{#2}{1}%
\expandafter\addtocounter{#2Prev}{1}
\xdef\temp{\csname #2 Eq\endcsname \ifnum\value{#2Prev}>0 \space(\csname #1\endcsname{#2Prev})\fi}%
\global\expandafter\let\csname #2\arabic{#2}\endcsname\temp%
\tag{\temp}%
}{%
\global\expandafter\newcounter{#2}%
\global\expandafter\newcounter{#2Prev}
\expandafter\addtocounter{#2}{1}%
\xdef\temp{\theequation \ifnum\value{#2Prev}>0 \space(\csname #1\endcsname{#2Prev})\fi}%
\xdef\eqonfamily{\theequation}%
\global\expandafter\let\csname #2 Eq\endcsname\eqonfamily%
\global\expandafter\let\csname #2\arabic{#2}\endcsname\temp%
\tag{\temp}%
\expandafter\addtocounter{equation}{1}
}%
}%
\newcommand\myFamRef[2][1]{\csname #2#1\endcsname}
\begin{document}
\section{test}
\begin{equation}
f(x)=3\cdot x
\end{equation}
\begin{equation}
x=4\cdot y \EqFamTag{MyFamily}
\end{equation}
As an example:
\begin{equation}
x=4\cdot 2=8\EqFamTag{MyFamily}
\end{equation}
The equation: \myFamRef[2]{MyFamily} is the first example/member of the equation \myFamRef{MyFamily}
\begin{equation}
x=4\cdot y
\end{equation}
Another example of :
\begin{equation}
x=4\cdot 2=8\EqFamTag{MyFamily}
\end{equation}
The equation: \myFamRef[3]{MyFamily} is the second example/member of the equation \myFamRef{MyFamily}
Another family of equations is:
\begin{equation}
f(x)=3+y \EqFamTag{NewFam}
\end{equation}
and a member of it is:
\begin{equation}
f(6)=9 \EqFamTag{NewFam}
\end{equation}
\end{document}
输出:
答案4
很容易将第一个(主)子方程编号为普通方程,子方程标准编号仅从第二个子方程开始:
\documentclass{article}
\usepackage{amsmath}
\setcounter{equation}{4}
\begin{document}
Some text . . . . . .
\begin{subequations}
\addtocounter{equation}{-1}
\begin{gather}
a+b \label{main} \\
3+2 \label{ex-1} \\
5\label{ex-2}
\end{gather}
\end{subequations}.
. . . . . .Some more text . . . . . .
\begin{equation}
c + d
\end{equation}
\eqref{ex-1} and \eqref{ex-2} illustrate \eqref{main}.
\end{document}