\documentclass[12pt, a4paper, UTF8, scheme = plain]{ctexrep}
\usepackage{amsmath,tasks}
\usepackage{graphicx}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse,breakable}
\tcbset{%
colback = white,
colframe = black,
title filled = false,
colbacktitle = white,
breakable,
enhanced
}%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
\NewTColorBox[
auto counter,
% number within = tcolorbox, %section ? chapter ? tcolorbox?
number freestyle = {Example \,\noexpand\arabic{\tcbcounter} }
]{example}{ O{}mo }{
fonttitle = \bfseries,
coltitle = black,
title = {\thetcbcounter: #2},
#1
}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{example}{box 1}
\begin{equation}
a + b = c
\end{equation}
\begin{equation}
a + b = c
\end{equation}
\begin{equation}
a + b = c
\end{equation}
\end{example}
How to start the equation numbering in the new box with $1$ again?
\begin{example}{box 2}
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\begin{equation}
a^3 + b^3 = c^3
\end{equation}
\begin{equation}
a + b = c
\end{equation}
\end{example}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
有这个选项吗number within
?我查看了手册,但关于它的介绍很少……
答案1
将equation
计数器重置0
为title
。\NewTColorBox
\documentclass[12pt, a4paper, UTF8, scheme = plain]{ctexrep}
\usepackage{amsmath,tasks}
\usepackage{graphicx}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse,breakable}
\tcbset{%
colback = white,
colframe = black,
title filled = false,
colbacktitle = white,
breakable,
enhanced
}%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
\NewTColorBox[
auto counter,
% number within = tcolorbox, %section ? chapter ? tcolorbox?
number freestyle = {Example \,\noexpand\arabic{\tcbcounter} }
]{example}{ O{}mo }{
fonttitle = \bfseries,
coltitle = black,
title = {\thetcbcounter: #2\setcounter{equation}{0}},
#1
}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{example}{box 1}
\begin{equation}
a + b = c
\end{equation}
\begin{equation}
a + b = c
\end{equation}
\begin{equation}
a + b = c
\end{equation}
\end{example}
How to start the equation numbering in the new box with $1$ again?
\begin{example}{box 2}
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\begin{equation}
a^3 + b^3 = c^3
\end{equation}
\begin{equation}
a + b = c
\end{equation}
\end{example}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}%%%%%%%%%%
答案2
equation
你应该为方框内的方程式定义一个特殊的计数器。用在每个环境下重置的特殊计数器替换计数器并不困难example
。
我还添加了对 的支持hyperref
。
\documentclass{article}
\usepackage{amsmath,tasks}
\usepackage{graphicx}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse,breakable}
\usepackage{hyperref}
\tcbset{
colback = white,
colframe = black,
title filled = false,
colbacktitle = white,
breakable,
enhanced
}
\NewTColorBox[
auto counter,
number freestyle = {Example \noexpand\arabic{\tcbcounter}}
]{example}{ O{}mo }{
fonttitle = \bfseries,
coltitle = black,
title = {\thetcbcounter: #2},
#1
}
\newcounter{boxequation}
\AddToHook{env/example/begin}{%
\setcounter{boxequation}{0}%
\ExpandArgs{cc}\let{c@equation}{c@boxequation}%
% comment the following line if you're not using hyperref
\renewcommand{\theHequation}{\arabic{\tcbcounter}\arabic{boxequation}}%
}
\begin{document}
\begin{example}{box 1}
Some text about this example
\begin{gather}
a + b = c \\
a + b = c \\
a + b = c
\end{gather}
Some text about this example
\end{example}
How to start the equation numbering in the new box with $1$ again?
\begin{example}{box 2}
Some text about this example
\begin{gather}
a^2 + b^2 = c^2 \\
a^3 + b^3 = c^3 \\
a + b = c
\end{gather}
Some text about this example
\end{example}
\end{document}