每解决一个问题后重置方程编号

每解决一个问题后重置方程编号

我开始使用 ShareLateX 基本家庭作业模板:

https://www.sharelatex.com/templates/examples/basic-homework-template

其中定义了“问题”和“解决方案”环境,定义为

\newenvironment{solution}[2][Solution]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

使用“align”环境,方程式编号为 (1)、(2) 等。但是,我希望方程式根据其所属的问题和相关解决方案进行编号。也就是说,我希望它们编号为 (problem#.equation#) 和 (solution#.equation#)。

例如,第一个问题/解决方案中的第二个方程式将是 (1.2)。不幸的是,我找不到任何资源可以为此提供任何指导。

答案1

只需将\newenvironment{problem}行替换为

\newenvironment{problem}[2][Problem]{\stepcounter{myproblemcnt}\setcounter{myproblemcnt}{#2}\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

并添加

\makeatletter
\renewcommand{\theequation}{\arabic{myproblemcnt}.\arabic{equation}}
\newcounter{myproblemcnt}
\@addtoreset{equation}{myproblemcnt}
\makeatother

你的序言。

完整 MWE:

\documentclass[12pt]{article}

\usepackage{answers}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{mathrsfs}
\usepackage[margin=1in]{geometry} 
\usepackage{amsmath,amsthm,amssymb}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\R}{\mathbb{R}}

\DeclareMathOperator{\sech}{sech}
\DeclareMathOperator{\csch}{csch}

\newenvironment{theorem}[2][Theorem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{definition}[2][Definition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{proposition}[2][Proposition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{lemma}[2][Lemma]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{exercise}[2][Exercise]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{solution}[2][Solution]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}
\newenvironment{problem}[2][Problem]{\stepcounter{myproblemcnt}\setcounter{myproblemcnt}{#2}\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{question}[2][Question]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{corollary}[2][Corollary]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

\makeatletter
\renewcommand{\theequation}{\arabic{myproblemcnt}.\arabic{equation}}
\newcounter{myproblemcnt}
\@addtoreset{equation}{myproblemcnt}
\makeatother

\begin{document}

% --------------------------------------------------------------
%                         Start here
% --------------------------------------------------------------

\title{Weekly Homework Template Tutorial}%replace with the appropriate homework number
\author{Your Name\\ %replace with your name
Course-Semester} %if necessary, replace with your course title

\maketitle
%Below is an example of the problem environment
\begin{problem}{6}
text.
\end{problem}

%Below is the solution environment
\begin{solution}{}
\begin{align}
a\\b\\c
\end{align}
\end{solution}

%Below is an example of the problem environment
\begin{problem}{13}
    text.
\end{problem}

%Below is the solution environment
\begin{solution}{}
\begin{align}
a\\b\\c
\end{align}
\end{solution}


\end{document}

结果

相关内容