是否可以以某种方式将章节号添加到计数器reaction
中chemmacros
,并在增加时重置它chapter
?在equation
和figure
等中,章节添加到计数器之前,例如 1.2,第一个数字表示章节,第二个数字表示图等,在report
/book
和 KOMA scrreprt
/中scrbook
。
梅威瑟:
\documentclass{scrreprt}
\usepackage{amsmath}
\usepackage{chemmacros}
\chemsetup{modules=reactions}
\begin{document}
\chapter{Reactions without chapter number}
With x.y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z
\begin{reaction}
H2O + H3O+ -> H2O2 + H+
\end{reaction}
\chapter{And repeat booth with counter resetting}
With (x.1).y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z, but incremented.
\begin{reaction}
H2O + H3O+ -> H2O2 + H+
\end{reaction}
\end{document}
答案1
该chemmacros
软件包\renewtagform
正好有这个功能(参见软件包文档第 35 页)。例如,使用方法如下:
\documentclass{scrreprt}
\usepackage{amsmath}
\usepackage{chemmacros}
\chemsetup{modules=reactions}
\renewtagform{reaction}[\thechapter.]{(}{)}
% Phelype Oleinik's answer added:
\makeatletter
\@addtoreset{reaction}{chapter}
\makeatother
\begin{document}
\chapter{Reactions without chapter number}
With x.y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z
\begin{reaction}
H2O + H3O+ -> H2O2 + H+
\end{reaction}
\chapter{And repeat booth with counter resetting}
With (x.1).y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z, but incremented.
\begin{reaction}
H2O + H3O+ -> H2O2 + H+
\end{reaction}
\end{document}
答案2
附带chngcntr
包装:
\documentclass{scrreprt}
\usepackage{amsmath}
\usepackage{chemmacros}
\chemsetup{modules=reactions}
\usepackage{chngcntr}
\counterwithin{reaction}{chapter}
\begin{document}
\chapter{Reactions chapter number}
With x.y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
With x.z
\begin{reaction}
H2O + H3O+ -> H2O2 + H+
\end{reaction}
\chapter{And repeat both with counter resetting}
With (x.1).y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
With x.z
\begin{reaction}
H2O + H3O+ -> H2O2 + H+
\end{reaction}
\end{document}
答案3
不需要额外的包或\makeatletter
定义:
\documentclass{scrreprt}
% \usepackage{amsmath} already loaded by `chemmacros'
\usepackage{chemmacros}
\chemsetup{modules=reactions}
\numberwithin{reaction}{chapter}% provided by the `amsmath' package
\begin{document}
\chapter{Reactions without chapter number}
With x.y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z
\begin{reaction}
H2O + H3O+ -> H2O2 + H+
\end{reaction}
\chapter{And repeat booth with counter resetting}
With (x.1).y
\begin{equation}
f(x)=e^{\frac{1}{x}}
\end{equation}
Only with z, but incremented.
\begin{reaction}
H2O + H3O+ -> H2O2 + H+
\end{reaction}
\end{document}
答案4
有一个命令\@addtoreset
,当另一个计数器增加时,会重置一个计数器。
只需将其添加到您的序言中:
\makeatletter
\@addtoreset{reaction}{chapter}
\makeatother
reaction
当chapter
计数器增加时,它将重置计数器。