自定义方程编号

自定义方程编号

我想标记一个方程

\[ 1 + 2 + \cdots + i = \frac{i(i+1)}{2} \eqname{Inequality(i)} \label{ineq} \]

涉及变量“i”作为(i)的函数,因此预期输出如下所示

[上述方程的 LaTeX 表示] (2.4)(i)

(实际上意味着有“i”个这样的方程)。(2.4)可能指的是第 2 节的方程 4。当我稍后访问该方程时,我希望它显示为

由于公式 (2.4)(n+1) 由公式 (2.4)(n) 得出,因此使用归纳法...

(编辑:改进措辞以澄清评论中的问题。)

答案1

让我们看看我是否猜对了你想要得到什么:

以下代码的输出

该输出由以下代码生成:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath}

\numberwithin{equation}{section}

\newcommand*{\myTagFormat}[2]{(\ref{#1})($#2$)}



\begin{document}

\section{First}

Just to include a couple of equations:
\begin{align}
      1 &= 1 \label{eq:one} \\
    1+2 &= 3 \label{eq:two}
\end{align}
Until now, we have equations \eqref{eq:one} and~\eqref{eq:two}.

\section{Second}

Still another equation of the same form:
\begin{equation}
    1+2+3 = 6 \label{eq:three}
\end{equation}
Generalizing equations \eqref{eq:one}, \eqref{eq:two}, and~\eqref{eq:three}, we 
claim that
% Little trick:
\refstepcounter{equation}\label{eq:base}% <-- Note!
\begin{equation}
    1+2+\dots+n = \frac{n(n+1)}{2}
    \tag*{\myTagFormat{eq:base}{n}}\label{eq:base-n}
\end{equation}
Now you can either:
\begin{itemize}
    \item
        reference equation~\ref{eq:base-n} directly (note that you must use
        \verb|\ref| instead of \verb|\eqref|, here), or
    \item
        say that equation~\myTagFormat{eq:base}{i+1} follows from
        equation~\myTagFormat{eq:base}{i} by adding $i+1$ on both sides of the
        latter.
\end{itemize}
One more equation to check that we haven't spoiled the numbering:
\begin{equation}
    x=y
\end{equation}

\end{document}

答案2

在此处输入图片描述

使用mathtoolspackage 命令\newtagform,您可以非常详细地自定义方程式编号。该命令的一般语法是:

\newtagform{label}[tag format]{left}{right}

只是label标记方法的唯一 ID,可以使用命令检索\usetagform{label}leftright应该写在标记左侧和右侧的内容(通常是括号)。tag format是您想要的标记的详细信息。根据您的具体情况,您可以使用以下语法:

[\renewcommand{\theequation}{(\arabic{chapter}.\arabic{section})(\roman{equation})}]

设置新的编号格式后,您还必须更改引用公式时的显示方式。对于您想要的样式,代码应该是:

\renewcommand{\theequation}{(\arabic{chapter}.\arabic{section})(\roman{equation})}

以下是此自定义编号如何工作的示例:

\documentclass[]{report}
\usepackage{amsmath}
\usepackage{amssymb, amsfonts}
\usepackage{gensymb}
\usepackage{mathtools}
    \newtagform{Alph}[\renewcommand{\theequation}{(\arabic{chapter}.\arabic{section})(\roman{equation})}]{}{}
    \usetagform{Alph}
\renewcommand{\theequation}{(\arabic{chapter}.\arabic{section})(\roman{equation})}


\begin{document}


\chapter{First Chapter}

\section{First Section}
\label{sec:one}

\begin{equation}
I = I_{ ph } -  
\overbrace{
    I_{ rs }
    \biggl[
    exp \biggl(
    \frac{V + I R_{s}}{a \thinspace V_{t}}
    \biggl) - 1   
    \biggl]
    % overbrace title
}^{ I_{d} }
-
\overbrace{
    \frac{V + I R_{s}}{R_{p}}
    % overbrace title
}^{I_{p}}
%
\label{eq:I_PV_m}
\end{equation}

\begin{equation}
\label{eq:R_p}
%
R_{p} = R_{p,ref}  \biggl(   \frac{G_{ref}}{G_{op}}  \biggl)   \biggl(  \frac{T_{op}}{T_{ref}}  \biggl)^{\delta_{p}}
\end{equation}


\begin{equation}
PMARE = \underset{i}{max} 
\biggl|  \frac{x_{i}-y_{i}}{y_{i}}  \biggl| \times 100\%
\quad i = 1, 2, \cdots , n
%
\label{eq:PMPARE}
\end{equation}


     A test for referencing Eqs. \ref{eq:I_PV_m}, \ref{eq:R_p}, and \ref{eq:PMPARE} which belong to Section \ref{sec:one}.


\section{Second Section}
\label{sec:two}

\begin{equation}
\label{eq:R_{s}}
%
R_{s} = R_{s,ref}  \biggl(   \frac{T_{op}}{T_{ref}} \biggl)^{\delta_{s}}
\end{equation}


\begin{align}
I_{ph} &= I_{sc} \frac{R_{s} + R_{p}}{R_{p}}  \notag
\\
&= I_{sc,ref} \bigg[  1 + \frac{\alpha}{100} (T_{op}-T_{ref}) \biggl]
\frac{G_{op}}{G_{ref}} \frac{R_{s} + R_{p}}{R_{p}}
%
\label{eq:I_ph}
\end{align}


    A test for referencing Eqs. \ref{eq:R_{s}} and \ref{eq:I_ph}which belong to Section \ref{sec:two}.


\end{document}

其他类型的编号选项包括\Roman(大写罗马字母)\alph\Alph。祝你好运

答案3

我第一次阅读时并没有真正理解这个问题,我以为你想要的是

但这并不完全是你想要的,因为我的答案不能给出像(n+1)这样的结果……但如果我们稍微改变一下,我们就可以得到这样的结果:

\makeatletter
\newcommand*\ifcounter[1]{%
  \ifcsname c@#1\endcsname%
    \expandafter\@firstoftwo%
  \else%
    \expandafter\@secondoftwo%
  \fi%
}%
\makeatother


\makeatletter
\newcommand\EqFamCustomTag[2]{%
\ifcounter{#1}{%
\expandafter\addtocounter{#1}{1}%
\xdef\temp{\csname #1 Eq\endcsname \space(#2)}%
\global\expandafter\let\csname #1\arabic{#1}\endcsname\temp%
\tag{\temp}%
}{%
\global\expandafter\newcounter{#1}%
\expandafter\addtocounter{#1}{1}%
\xdef\temp{\theequation\space(#2)}%
\xdef\eqonfamily{\theequation}%
\global\expandafter\let\csname #1 Eq\endcsname\eqonfamily%
\global\expandafter\let\csname #1\arabic{#1}\endcsname\temp%
\tag{\temp}%
\expandafter\addtocounter{equation}{1}
}%
}%
\makeatother

可以像这样使用:

\begin{equation}
 \frac{x^2}{2}+\frac{3\cdot y^2}{10}=2\EqFamCustomTag{Elliptic}{n+1}
\end{equation}

并给你你想要的...(我希望)...对于你有的其他方程式的自动编号,你可以使用我提到的问答之一(这个问题也开始了......)

相关内容