我想要两个类似方程的环境,带有单独的编号,并且可以在各种 amsmath 环境中轻松使用它们。
受到 Egreg 的回答的启发克隆具有不同间距的 `amsmath` 方程环境, 我写
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\newcounter{savedequation} \newcounter{myhypo}
\newcommand{\setmyhypo}{%
\setcounter{savedequation}{\value{equation}}%
\setcounter{equation}{\value{myhypo}}%
\renewcommand\theequation{$H_\arabic{equation}$}%
}
\newcommand{\unsetmyhypo}{%
\setcounter{myhypo}{\value{equation}}%
\setcounter{equation}{\value{savedequation}}%
}
\newenvironment{hypothesis}{%
\setmyhypo%
\begin{equation}%
}{%
\end{equation}%
\unsetmyhypo%
}
\begin{document}
\begin{hypothesis} \label{test_1} a=b \end{hypothesis}
\begin{gather}
\label{test_2} c=d \\
\setmyhypo
\notag e=f \\
\label{test_3} h=i
\unsetmyhypo
\end{gather}
\setmyhypo
\begin{gather}
\label{test_4} j=k \\
\notag l=m
\end{gather}
\unsetmyhypo
\eqref{test_1}, \eqref{test_2} and \eqref{test_4} work but not \eqref{test_3}.
\end{document}
关于如何在同一个聚集中使用两个类似方程的环境,有什么想法吗(为了对齐目的,它可能更清晰)?
编辑:改进:
\makeatletter
\newcommand{\setmyhypo}{%
\setcounter{savedequation}{\value{equation}}%
\setcounter{equation}{\value{myhypo}}%
\renewcommand\theequation{$H_{\arabic{equation}}$}%
\tagsleft@true\let\veqno\@@leqno%
}
\newcommand{\unsetmyhypo}{%
\setcounter{myhypo}{\value{equation}}%
\setcounter{equation}{\value{savedequation}}%
\renewcommand\theequation{\arabic{equation}}%
\tagsleft@false\let\veqno\@@eqno%
}
\makeatother
答案1
使用\tag
(与执行必要操作的代码一起)。
我对代码做了一些更改,请检查一下。
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\newcounter{savedequation}
\newcounter{myhypo}
\renewcommand\themyhypo{\ensuremath{\mathrm{H}_{\arabic{myhypo}}}}
\newcommand{\setmyhypo}{%
\setcounter{savedequation}{\value{equation}}%
\setcounter{equation}{\value{myhypo}}%
\renewcommand\theequation{\ensuremath{\mathrm{H}_{\arabic{equation}}}}%
}
\newcommand{\unsetmyhypo}{%
\setcounter{myhypo}{\value{equation}}%
\setcounter{equation}{\value{savedequation}}%
}
\newenvironment{hypothesis}{%
\setmyhypo
\begin{equation}%
}{%
\end{equation}%
\unsetmyhypo
\ignorespacesafterend
}
\newcommand{\hypoline}{\stepcounter{myhypo}\tag{\themyhypo}}
\begin{document}
\begin{hypothesis}\label{test_1}
a=b
\end{hypothesis}
\begin{gather}
c=d \label{test_2} \\
e=f \notag \\
h=i \hypoline \label{test_3} \\
u=v
\end{gather}
\setmyhypo
\begin{gather}
j=k \label{test_4} \\
l=m \notag
\end{gather}
\unsetmyhypo
\eqref{test_1}, \eqref{test_2} and \eqref{test_4} work and also does \eqref{test_3}.
\end{document}