2

enter image description here

I have a problem with my theorem and examples/definitions numbering. For my theorem environment I used the mdframed packages but for my definitions/examples I used \newtheorem{}{}. Here you can see that my theorem is numbered 3.5.1 but also my example is numbered as 3.5.1! How can I get a numeration like Theorem 3.5.1 and Example 3.5.2 and so on? Here there is my code:

\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}%
}
2

You want that the environments share the theo counter:

\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}

Full code

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.