当我开始新问题时,案例的枚举不会从 1 重新开始。有人能帮我解决这个问题吗?

当我开始新问题时,案例的枚举不会从 1 重新开始。有人能帮我解决这个问题吗?
\documentclass[28pt]{article}

\usepackage{fancyhdr}

\usepackage[includeheadfoot,margin=1.0cm]{geometry} 
\usepackage{amsmath,amsthm,amssymb}
\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{framed}
\usepackage{chessfss} %chess figure for HW #2
\usepackage[english]{babel} %table for problem A.43
\usepackage{multirow} %table for problem A.43
\usepackage[table]{xcolor} %color certain blocks in a table
%\usepackage[pass,showframe]{geometry}  just to show the margins
\usepackage[makeroom]{cancel}
\usepackage{array}  %BETWEEN TWO 2-DIGIT NUMBERS
\usepackage{graphicx}
\usepackage{multicol}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\thedate}{\today}


\newtheoremstyle{case}{}{}{}{}{}{:}{ }{}
\theoremstyle{case}
\newtheorem{case}{Case}


\newenvironment{theorem}[2][Theorem]{\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{problem}[2][Problem]{\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}}

\begin{document}


\begin{problem}{1} 
 Create an enumerated case
\begin{case}
This is case 1
\end{case}

\begin{case}
This is case 2
\end{case}

\end{problem}

\begin{problem}{2}
Welcome to my life
\begin{case}
This should be case 1 since this is a new problem, but something is wrong
\end{case}

\begin{case}
 Again can you see the enumeration is off. How can I fix this?
\end{case}
\end{problem}


\end{document}

答案1

要重置每个已定义环境的案例编号,必须case在离开环境时使用 手动重置计数器\setcounter{case}{0}。这里我展示了我是如何做到的。

\documentclass[28pt]{article}

\usepackage{fancyhdr}

\usepackage[includeheadfoot,margin=1.0cm]{geometry} 
\usepackage{amsmath,amsthm,amssymb}
\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{framed}
\usepackage{chessfss} %chess figure for HW #2
\usepackage[english]{babel} %table for problem A.43
\usepackage{multirow} %table for problem A.43
\usepackage[table]{xcolor} %color certain blocks in a table
%\usepackage[pass,showframe]{geometry}  just to show the margins
\usepackage[makeroom]{cancel}
\usepackage{array}  %BETWEEN TWO 2-DIGIT NUMBERS
\usepackage{graphicx}
\usepackage{multicol}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\thedate}{\today}


\newtheoremstyle{case}{}{}{}{}{}{:}{ }{}
\theoremstyle{case}
\newtheorem{case}{Case}


\newenvironment{theorem}[2][Theorem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}%
  \setcounter{case}{0}}
\newenvironment{lemma}[2][Lemma]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}%
  \setcounter{case}{0}}
\newenvironment{exercise}[2][Exercise]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}%
  \setcounter{case}{0}}
\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}%
  \setcounter{case}{0}}
\newenvironment{question}[2][Question]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}%
  \setcounter{case}{0}}
\newenvironment{corollary}[2][Corollary]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}%
  \setcounter{case}{0}}

\begin{document}


\begin{problem}{1} 
 Create an enumerated case
\begin{case}
This is case 1
\end{case}

\begin{case}
This is case 2
\end{case}

\end{problem}

\begin{problem}{2}
Welcome to my life
\begin{case}
This should be case 1 since this is a new problem, but something is wrong
\end{case}

\begin{case}
 Again can you see the enumeration is off. How can I fix this?
\end{case}
\end{problem}


\end{document}

在此处输入图片描述

相关内容