我想要两个计数器,部分和练习次数。我有这个示例代码
\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\newcounter{header}
\setcounter{header}{1}
\newcommand{\Header}[1]{
\begin{center}
#1 Practices Set \theheader
\setcounter{exercice}{0}
\addtocounter{header}{1}
\end{center}
}
\newtheorem{exercice}{Exercice}[header]
\begin{document}
\Header{Matrices.}
\begin{exercice} This is the first Exercise of Set 1 numbered as 2.1. I would like to number it as 1.1
\end{exercice}
\begin{exercice} This is the second Exercise of Set 1 numbered as 2.2. I would like to number it as 1.2
\end{exercice}
\Header{Systems of Linear Equations.}
\begin{exercice}
This is the first Exercise of Set 2 numbered as 3.1. I would like to number it as 2.1
\end{exercice}
\end{document}
答案1
这解决了你的问题,甚至可以引用标题
\newcounter{header}
\newcommand{\Header}[1]{
\refstepcounter{header}
\begin{center}
#1 Practices Set \theheader
\end{center}
}
首先,的起始值header
应为 0(默认情况下为 ,您实际上可以删除\setcounter{header}{0}
)。其次,header
在使用它之前,您应该对其进行升级,\Header
否则就没有意义了。第三,正如您使用 一样\newtheorem{exercice}{Exercice}[header]
,exercise
每当 发生变化时都会自动重置header
,因此无需手动执行此操作。