使用多个计数器对方程式进行编号

使用多个计数器对方程式进行编号

我最近在发数学讲义,想在其中添加一个包含练习的小节。讲义的编号是 (sec.eq​​),但对于练习,我希望编号为 (sec.ex.eq)。我不知道如何实现这一点。

(2017 年 9 月 6 日) 感谢您迄今为止的评论。提供一份最简短的文档:

\documentclass{article}

\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{hyperref}

\newtheorem{Exercise}{Exercise}[section]

\begin{document}

\section{sec1}
Here is section 1.
\subsection{ssec1.1}
Here I have a subsection.
\subsection{ssec1.2}
Here I have another subsection.
\subsection{exercises1}
Here I have the exercises (using the above defined theroem enviroment).

\section{sec2}
Here the same.
\subsection{ssec2.1}
Here the same.
\subsection{ssec2.2}
Here the same.
\subsection{exercises2}
And again exercises.
\end{document}

编号是关于方程式编号的,我在那里遇到了我的问题。

答案1

的输出可以在通过以下方式定义的环境\theequation中本地更改:Exercise\newtheorem

\AtBeginEnvironment{Exercise}{%
  \renewcommand{\theequation}{\theExercise.\arabic{equation}}
}

由于这发生在环境组内,因此重新定义不会影响\theequation使用\begin{equation}...\end{equation}

由于Exercise定义为在内计算section\theExercise因此已\thesection.\arabic{Exercise}按设计使用。

请注意,这里方程计数器不会每次都重置Exercise

\documentclass{article}

\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{etoolbox}


\usepackage{hyperref}

\newtheorem{Exercise}{Exercise}[section]

\AtBeginEnvironment{Exercise}{%
  \renewcommand{\theequation}{\theExercise.\arabic{equation}}
}



\begin{document}

\section{sec1}
Here is section 1.

% Regular equation environment, using a different counter. 

\begin{equation}
  E = mc^{2}
\end{equation}
\subsection{ssec1.1}
Here I have a subsection.
\subsection{ssec1.2}
Here I have another subsection.
\subsection{exercises1}
Here I have the exercises (using the above defined theroem enviroment).

\begin{Exercise}
  \begin{equation}
    E = mc^{2}
    \end{equation}

And other equations:

\begin{align}
  E^{2} &= (p c)^{2} + (m_{0} c^{2})^{2} \\
  c^{2} &= a^{2} + b^{2} 
\end{align}

\end{Exercise}




\section{sec2}
Here the same.
\subsection{ssec2.1}
Here the same.
\subsection{ssec2.2}
Here the same.
\subsection{exercises2}
And again exercises.

\begin{Exercise}
  \begin{equation}
    E = mc^{2}
    \end{equation}

And other equations:

\begin{align}
  E^{2} &= (p c)^{2} + (m_{0} c^{2})^{2} \\
  c^{2} &= a^{2} + b^{2} 
\end{align}

\end{Exercise}

\end{document}

在此处输入图片描述

相关内容