为了在公式编号中添加字母,我使用了以下代码
\newcounter{defcounter}
\setcounter{defcounter}{0}
\newenvironment{eee}[1]{%
\addtocounter{equation}{-1}
\refstepcounter{defcounter}
\renewcommand\theequation{E.#1.\thedefcounter}
\begin{equation}}
{\end{equation}}
现在我应该怎么做才能将此代码扩展到align
环境?
答案1
您可以使用以下基础设施subequations
:
\documentclass{article}
\usepackage{amsmath}
\newenvironment{eee}[2][equation]
{\subequations\def\eeecurrent{#1}%
\renewcommand\theequation{E.#2.\arabic{equation}}%
\csname #1\endcsname}
{\csname end\eeecurrent\endcsname
\endsubequations\addtocounter{equation}{-1}}
\begin{document}
\begin{equation}
1=1
\end{equation}
\begin{eee}{one}
a=b
\end{eee}
\begin{eee}[align]{two}
a&=b\\
c&=d
\end{eee}
\begin{equation}
1=1
\end{equation}
\end{document}
在咨询了我的水晶球后,出现了一种变体:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{exercise}{Exercise}
\newcounter{exnumber}[exercise]
\newenvironment{eee}[1][equation]
{\addtocounter{equation}{-1}%
\subequations\def\eeecurrent{#1}%
\setcounter{equation}{\value{exnumber}}%
\renewcommand\theequation{E.\theexercise.\arabic{equation}}%
\csname #1\endcsname}
{\csname end\eeecurrent\endcsname
\setcounter{exnumber}{\value{equation}}%
\endsubequations}
\begin{document}
\begin{equation}
1=1
\end{equation}
\begin{exercise}
Prove the following
\begin{eee}
a=b
\end{eee}
\end{exercise}
\begin{exercise}
Prove the following
\begin{eee}[align]
a&=b\\
c&=d
\end{eee}
and also the following
\begin{eee}[gather]
a=b\\
c=d
\end{eee}
\end{exercise}
\begin{equation}
1=1
\end{equation}
\end{document}