定理版本编号从 1.0 开始,而不是 1.1

定理版本编号从 1.0 开始,而不是 1.1

我如何使以下文件中的编号从1.0而不是1.1? 开始,setcounter{dfnv}{-1}但没有任何作用。

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}

\newcounter{dfnq}[section]
\newcounter{dfnv}

\makeatletter
\@addtoreset{dfnv}{dfnq}
\let\thedfnvsaved\thedfnv
\renewcommand{\thedfnv}{\thedfnq.\thedfnvsaved}
\makeatother

%% \makeatletter
%% \@namedef{thedfnv}{\@nameuse{thedfnq}.\arabic{dfnv}}
%% \makeatother

\newtheorem{dfn}[dfnv]{Definition}

\begin{document}

\section{First section}


\stepcounter{dfnq}
% Should display as Definition 1.0
% Actually displays as Definition 1.1
\begin{dfn}
  Version 0 of the definition of foo.
\end{dfn}

% Should display as Definition 1.1
% Actually displays as Definition 1.2
\begin{dfn}
  Version 1 of the definition of foo.
\end{dfn}
\stepcounter{dfnq}

% Should display as Definition 2.0
% Actually displays as Definition 2.1
\begin{dfn}
  Version 0 of the definition of bar.
\end{dfn}

% Should display as Definition 2.1
% Actually displays as Definition 2.2
\begin{dfn}
  Version 1 of the definition of bar.
\end{dfn}
\stepcounter{dfnq}

\end{document}

全面披露:这是我之前的问题

答案1

您需要做的就是在使用计数器时将其值减 1(在 中\thedfnv)。这里使用临时计数器完成此操作。

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}

\newcounter{dfnq}[section]
\newcounter{dfnv}[dfnq]
\newcounter{tmpcnt}

\renewcommand{\thedfnv}{
\setcounter{tmpcnt}{\value{dfnv}}\addtocounter{tmpcnt}{-1}\thedfnq.\thetmpcnt}


\newtheorem{dfn}[dfnv]{Definition}

\begin{document}

\section{First section}


\stepcounter{dfnq}
% Should display as Definition 1.0
% Actually displays as Definition 1.1
\begin{dfn}
  Version 0 of the definition of foo.
\end{dfn}

% Should display as Definition 1.1
% Actually displays as Definition 1.2
\begin{dfn}
  Version 1 of the definition of foo.
\end{dfn}
\stepcounter{dfnq}

% Should display as Definition 2.0
% Actually displays as Definition 2.1
\begin{dfn}
  Version 0 of the definition of bar.
\end{dfn}

% Should display as Definition 2.1
% Actually displays as Definition 2.2
\begin{dfn}
  Version 1 of the definition of bar.
\end{dfn}
\stepcounter{dfnq}

\end{document}

编辑:让标签正常工作的方法

  • 解耦dfnv形式dfnq(不是绝对必要的,但我们将手动处理依赖关系)
  • 初始化dfnv-1
  • 定义一个\nextdef您将调用的命令来代替\stepcounter{dfnq}

    \newcommand{\nextdef}{\stepcounter{dfnq}\setcounter{dfnv}{-1}}

  • 重新定义\thedfnv旧方法:

    \renewcommand{\thedfnv}{\thedfnq.\arabic{dfnv}}

好了,现在应该可以正常工作了。

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}

\newcounter{dfnq}[section]
\newcounter{dfnv}
\setcounter{dfnv}{-1}

\renewcommand{\thedfnv}{\thedfnq.\arabic{dfnv}}

\def\nextdef{\stepcounter{dfnq}\setcounter{dfnv}{-1}}

\newtheorem{dfn}[dfnv]{Definition}

\begin{document}

\section{First section}


\stepcounter{dfnq}
% Should display as Definition 1.0
% Actually displays as Definition 1.1
\begin{dfn}\label{defa}
  Version 0 of the definition of foo.
\end{dfn}

% Should display as Definition 1.1
% Actually displays as Definition 1.2
\begin{dfn}\label{defb}
  Version 1 of the definition of foo.
\end{dfn}
\nextdef

% Should display as Definition 2.0
% Actually displays as Definition 2.1
\begin{dfn}\label{defc}
  Version 0 of the definition of bar.
\end{dfn}

% Should display as Definition 2.1
% Actually displays as Definition 2.2
\begin{dfn}\label{defd}
  Version 1 of the definition of bar.
\end{dfn}
\nextdef

\ref{defa}

\ref{defb}

\ref{defc}

\ref{defd}

\end{document}

答案2

放在\setcounter{dfnv}{\numexpr\value{dfnv}-1\relax}每次出现的 之后\stepcounter{dfnq}

\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}

\newcounter{dfnq}[section]
\newcounter{dfnv}

\makeatletter
\@addtoreset{dfnv}{dfnq}
\let\thedfnvsaved\thedfnv
\renewcommand{\thedfnv}{\thedfnq.\thedfnvsaved}
\makeatother

%% \makeatletter
%% \@namedef{thedfnv}{\@nameuse{thedfnq}.\arabic{dfnv}}
%% \makeatother

\newtheorem{dfn}[dfnv]{Definition}

\begin{document}

\section{First section}


\stepcounter{dfnq}
\setcounter{dfnv}{\numexpr\value{dfnv}-1\relax}
% Should display as Definition 1.0
% Actually displays as Definition 1.1
\begin{dfn}
  Version 0 of the definition of foo.
\end{dfn}

% Should display as Definition 1.1
% Actually displays as Definition 1.2
\begin{dfn}
  Version 1 of the definition of foo.
\end{dfn}
\stepcounter{dfnq}
\setcounter{dfnv}{\numexpr\value{dfnv}-1\relax}
% Should display as Definition 2.0
% Actually displays as Definition 2.1
\begin{dfn}
  Version 0 of the definition of bar.
\end{dfn}

% Should display as Definition 2.1
% Actually displays as Definition 2.2
\begin{dfn}
  Version 1 of the definition of bar.
\end{dfn}
\stepcounter{dfnq}

\end{document}

在此处输入图片描述

答案3

\setcounter{dfnq}{-1} 并随后...

相关内容