定义/例子和定理编号的问题

定义/例子和定理编号的问题

在此处输入图片描述

我的定理和示例/定义编号有问题。对于我的定理环境,我使用了 mdframed 包,但对于我的定义/示例,我使用了\newtheorem{}{}。在这里你可以看到我的定理编号为 3.5.1,但我的示例编号为 3.5.1!我怎样才能得到像定理 3.5.1 和示例 3.5.2 等这样的编号?这是我的代码:

\usepackage[framemethod=TikZ]{mdframed}

\newcounter{theo}[section]
\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{chapter}.\arabic{section}.\arabic{theo}}

\theoremstyle{definition}
\newtheorem{definizione}{Definizione}[section]
\newtheorem{esempio}[definizione]{Esempio}
\newtheorem{algoritmo}[definizione]{Algoritmo}
\newtheorem{osservazione}[definizione]{Osservazione}
\theoremstyle{plain}
\newtheorem{corollario}[definizione]{Corollario}
\newtheorem{proposizione}[definizione]{Proposizione}


\newenvironment{theo}[2][]{%
   \refstepcounter{theo}%
   \ifstrempty{#1}%
      {\mdfsetup{%
         frametitle={%
            \tikz[baseline=(current bounding box.east),outer sep=0pt]
            \node[anchor=east,rectangle,fill=black!20]
            {\strut Teorema~\thetheo};}%
         }%
      }%
      {\mdfsetup{%
         frametitle={%            
            \tikz[baseline=(current bounding box.east),outer sep=0pt]
            \node[anchor=east,rectangle,fill=black!20]
            {\strut Teorema~\thetheo~(#1).};}%
         }%
      }%
   \mdfsetup{innertopmargin=10pt,linecolor=black!30,%
             linewidth=2pt,topline=true,%
             frametitleaboveskip=\dimexpr-\ht\strutbox\relax}
   \begin{mdframed}[backgroundcolor=gray!10]\relax\label{#2}}{\end{mdframed}%
}

答案1

您希望环境共享计数器theo

\theoremstyle{definition}
\newtheorem{definizione}[theo]{Definizione}
\newtheorem{esempio}[theo]{Esempio}
\newtheorem{algoritmo}[theo]{Algoritmo}
\newtheorem{osservazione}[theo]{Osservazione}
\theoremstyle{plain}
\newtheorem{corollario}[theo]{Corollario}
\newtheorem{proposizione}[theo]{Proposizione}

完整代码

\documentclass{book}
\usepackage{amsthm}

\usepackage[framemethod=TikZ]{mdframed}

\newcounter{theo}[section]
\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{chapter}.\arabic{section}.\arabic{theo}}

\theoremstyle{definition}
\newtheorem{definizione}[theo]{Definizione}
\newtheorem{esempio}[theo]{Esempio}
\newtheorem{algoritmo}[theo]{Algoritmo}
\newtheorem{osservazione}[theo]{Osservazione}
\theoremstyle{plain}
\newtheorem{corollario}[theo]{Corollario}
\newtheorem{proposizione}[theo]{Proposizione}


\newenvironment{theo}[2][]{%
   \refstepcounter{theo}%
   \ifstrempty{#1}%
      {\mdfsetup{%
         frametitle={%
            \tikz[baseline=(current bounding box.east),outer sep=0pt]
            \node[anchor=east,rectangle,fill=black!20]
            {\strut Teorema~\thetheo};}%
         }%
      }%
      {\mdfsetup{%
         frametitle={%            
            \tikz[baseline=(current bounding box.east),outer sep=0pt]
            \node[anchor=east,rectangle,fill=black!20]
            {\strut Teorema~\thetheo~(#1).};}%
         }%
      }%
   \mdfsetup{innertopmargin=10pt,linecolor=black!30,%
             linewidth=2pt,topline=true,%
             frametitleaboveskip=\dimexpr-\ht\strutbox\relax}
   \begin{mdframed}[backgroundcolor=gray!10]\relax\label{#2}}{\end{mdframed}%
}


\begin{document}

\chapter{A}
\section{A}

\begin{theo}[Abc]{label}
Something
\end{theo}

\begin{esempio}
Example
\end{esempio}

\end{document}

在此处输入图片描述

相关内容