Consecutive numbering and labels in tcolorbox












3















Those days I write a book, and I use framed boxes tcolorbox. Have a look:



documentclass[12pt,a4paper]{book}
usepackage[utf8]{inputenc}
usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
usepackage[english]{babel}
usepackage{graphicx}
usepackage{textcomp}
usepackage{tcolorbox,xcolor}
theoremstyle{definition}

makeatletter

tcbuselibrary{theorems}

newtcbtheorem[number within=section]{mytheo}{Theorem}%
{colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

newtcbtheorem[number within=section]{myprop}{Proposition}%
{colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

newtcbtheorem[number within=section]{mylem}{Lemma}%
{colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

newtcbtheorem[number within=section]{mypor}{Corollary}%
{colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

newtcbtheorem[number within=section]{myax}{Axiom}%
{colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


renewcommand{rmdefault}{udidot}

begin{document}

newtheorem{defin}{Definition}[section]
newtheorem{prt}{Remark}[section]
newtheorem{prts}{Remarks}[section]
newtheorem{exmp}{Example}[section]
newtheorem{exmps}{Examples}[section]
newtheorem*{note}{Note}

chapter{Maximal and Prime Ideals}

section{Maximal Ideals}

begin{defin}
Let $R$ a commutative ring with $1_R$ ...
end{defin}

begin{myprop}{Maximal Ideals Criterion}{}
label{Max Id Crit}
Let $R$ a commutative ring with $1_R$ ...
end{myprop}

From the Proposition ref{Max Id Crit}, ...

end{document}


As you can see, I would like to use these frames only for theorems, propositions, lemmas, corollaries and axioms (and not for the definitions). Also I would like to keep the choice to write some of them (for instance, a theorem) without these frames.



My questions are:




  1. How can we have consecutive numbering in the whole text?

  2. Ase you can see, we face a problem with labels in the reference of theorems etc. How can we solve it?


enter image description here










share|improve this question



























    3















    Those days I write a book, and I use framed boxes tcolorbox. Have a look:



    documentclass[12pt,a4paper]{book}
    usepackage[utf8]{inputenc}
    usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
    usepackage[english]{babel}
    usepackage{graphicx}
    usepackage{textcomp}
    usepackage{tcolorbox,xcolor}
    theoremstyle{definition}

    makeatletter

    tcbuselibrary{theorems}

    newtcbtheorem[number within=section]{mytheo}{Theorem}%
    {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

    newtcbtheorem[number within=section]{myprop}{Proposition}%
    {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

    newtcbtheorem[number within=section]{mylem}{Lemma}%
    {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

    newtcbtheorem[number within=section]{mypor}{Corollary}%
    {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

    newtcbtheorem[number within=section]{myax}{Axiom}%
    {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


    renewcommand{rmdefault}{udidot}

    begin{document}

    newtheorem{defin}{Definition}[section]
    newtheorem{prt}{Remark}[section]
    newtheorem{prts}{Remarks}[section]
    newtheorem{exmp}{Example}[section]
    newtheorem{exmps}{Examples}[section]
    newtheorem*{note}{Note}

    chapter{Maximal and Prime Ideals}

    section{Maximal Ideals}

    begin{defin}
    Let $R$ a commutative ring with $1_R$ ...
    end{defin}

    begin{myprop}{Maximal Ideals Criterion}{}
    label{Max Id Crit}
    Let $R$ a commutative ring with $1_R$ ...
    end{myprop}

    From the Proposition ref{Max Id Crit}, ...

    end{document}


    As you can see, I would like to use these frames only for theorems, propositions, lemmas, corollaries and axioms (and not for the definitions). Also I would like to keep the choice to write some of them (for instance, a theorem) without these frames.



    My questions are:




    1. How can we have consecutive numbering in the whole text?

    2. Ase you can see, we face a problem with labels in the reference of theorems etc. How can we solve it?


    enter image description here










    share|improve this question

























      3












      3








      3








      Those days I write a book, and I use framed boxes tcolorbox. Have a look:



      documentclass[12pt,a4paper]{book}
      usepackage[utf8]{inputenc}
      usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
      usepackage[english]{babel}
      usepackage{graphicx}
      usepackage{textcomp}
      usepackage{tcolorbox,xcolor}
      theoremstyle{definition}

      makeatletter

      tcbuselibrary{theorems}

      newtcbtheorem[number within=section]{mytheo}{Theorem}%
      {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

      newtcbtheorem[number within=section]{myprop}{Proposition}%
      {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

      newtcbtheorem[number within=section]{mylem}{Lemma}%
      {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

      newtcbtheorem[number within=section]{mypor}{Corollary}%
      {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

      newtcbtheorem[number within=section]{myax}{Axiom}%
      {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


      renewcommand{rmdefault}{udidot}

      begin{document}

      newtheorem{defin}{Definition}[section]
      newtheorem{prt}{Remark}[section]
      newtheorem{prts}{Remarks}[section]
      newtheorem{exmp}{Example}[section]
      newtheorem{exmps}{Examples}[section]
      newtheorem*{note}{Note}

      chapter{Maximal and Prime Ideals}

      section{Maximal Ideals}

      begin{defin}
      Let $R$ a commutative ring with $1_R$ ...
      end{defin}

      begin{myprop}{Maximal Ideals Criterion}{}
      label{Max Id Crit}
      Let $R$ a commutative ring with $1_R$ ...
      end{myprop}

      From the Proposition ref{Max Id Crit}, ...

      end{document}


      As you can see, I would like to use these frames only for theorems, propositions, lemmas, corollaries and axioms (and not for the definitions). Also I would like to keep the choice to write some of them (for instance, a theorem) without these frames.



      My questions are:




      1. How can we have consecutive numbering in the whole text?

      2. Ase you can see, we face a problem with labels in the reference of theorems etc. How can we solve it?


      enter image description here










      share|improve this question














      Those days I write a book, and I use framed boxes tcolorbox. Have a look:



      documentclass[12pt,a4paper]{book}
      usepackage[utf8]{inputenc}
      usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
      usepackage[english]{babel}
      usepackage{graphicx}
      usepackage{textcomp}
      usepackage{tcolorbox,xcolor}
      theoremstyle{definition}

      makeatletter

      tcbuselibrary{theorems}

      newtcbtheorem[number within=section]{mytheo}{Theorem}%
      {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

      newtcbtheorem[number within=section]{myprop}{Proposition}%
      {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

      newtcbtheorem[number within=section]{mylem}{Lemma}%
      {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

      newtcbtheorem[number within=section]{mypor}{Corollary}%
      {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

      newtcbtheorem[number within=section]{myax}{Axiom}%
      {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


      renewcommand{rmdefault}{udidot}

      begin{document}

      newtheorem{defin}{Definition}[section]
      newtheorem{prt}{Remark}[section]
      newtheorem{prts}{Remarks}[section]
      newtheorem{exmp}{Example}[section]
      newtheorem{exmps}{Examples}[section]
      newtheorem*{note}{Note}

      chapter{Maximal and Prime Ideals}

      section{Maximal Ideals}

      begin{defin}
      Let $R$ a commutative ring with $1_R$ ...
      end{defin}

      begin{myprop}{Maximal Ideals Criterion}{}
      label{Max Id Crit}
      Let $R$ a commutative ring with $1_R$ ...
      end{myprop}

      From the Proposition ref{Max Id Crit}, ...

      end{document}


      As you can see, I would like to use these frames only for theorems, propositions, lemmas, corollaries and axioms (and not for the definitions). Also I would like to keep the choice to write some of them (for instance, a theorem) without these frames.



      My questions are:




      1. How can we have consecutive numbering in the whole text?

      2. Ase you can see, we face a problem with labels in the reference of theorems etc. How can we solve it?


      enter image description here







      cross-referencing numbering tcolorbox labels






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 13 at 19:58









      ChrisChris

      1506




      1506






















          2 Answers
          2






          active

          oldest

          votes


















          5















          1. The tcbtheorem environments allow you to use counters from other tcbtheorems as well as existing LaTeX counters. It will be easier to define the standard LaTeX theorems first (all sharing the same counter), and then define the tcbtheorems (using that same counter).

          2. The problem is that a label for a tcbtheorem environment needs to be passed as an option to that environment in order for it to work correctly. This is not standard LaTeX behaviour (you would have noticed that labelling and referencing your definition environment would have worked without a hitch).


          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}
          % Define amsthm theorems first
          newtheorem{defin}{Definition}[section] % Creates a new counter, number within section
          newtheorem{prt}[defin]{Remark} % Putting [defin] in second position uses defin's counter instead of creating a new one
          newtheorem{prts}[defin]{Remarks} % Again share defin's counter
          newtheorem{exmp}[defin]{Example} % etc.
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          tcbuselibrary{theorems}
          % use counter*=defin to make each tcbtheorem share defin's counter
          newtcbtheorem[use counter*=defin, number within=section]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mypor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}
          renewcommand{rmdefault}{udidot}
          begin{document}
          chapter{Maximal and Prime Ideals}
          section{Maximal Ideals}
          % Normal labelling
          begin{defin} label{first_def}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}
          % tcbtheorem labelling
          begin{myprop}[label=prop:maximal]{Maximal Ideals Criterion}{}
          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}
          From the Proposition ref{prop:maximal} and definition ref{first_def}ldots
          end{document}


          Output:



          output



          As an aside, I would recommend using the cleveref package which can easily be set-up with the each tcbtheorem so as to produce a named reference instead of just a number e.g. 'proposition 1.1.2' vs '1.1.2'. That way you don't have to worry about whether you're referencing a theorem, or a definition, or a proposition etc. each time.



          FYI There was a rogue makeatletter in your code.






          share|improve this answer


























          • Works perfect, thank you. But, why makeatletter is a rogue?

            – Chris
            Feb 13 at 22:08






          • 1





            It wasn't doing anything. In general makeatletter should only be used 'temporarily', being following shortly by makeatother.

            – Pippip19
            Feb 14 at 6:38











          • Ok, thank you very much!

            – Chris
            Feb 15 at 20:56



















          4














          The key is the tcolorbox options use counter=<another counter> and use counter from= <counter from another tcolorbox>



          Update taking into account the OP comments:



          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}

          %makeatletter

          tcbuselibrary{theorems}

          newtcbtheorem[number within=section,use counter=defin]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter =defin]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter= defin]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{mycor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


          renewcommand{rmdefault}{udidot}

          begin{document}

          newtheorem{defin}{Definition}[section]
          newtheorem{prt}[defin]{Remark}
          newtheorem{prts}[defin]{Remarks}
          newtheorem{exmp}[defin]{Example}%[section]
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          chapter{Maximal and Prime Ideals}

          section{Maximal Ideals}

          begin{defin}
          label{def:commutative ring}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}

          begin{myprop}{Maximal Ideals Criterion}{Max Id Crit}

          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}

          From the Proposition ref{th:Max Id Crit},

          See definition ref{def:commutative ring}

          begin{exmp} label{ex: my example}
          my example
          end{exmp}

          example : ref{ex: my example}



          end{document}


          enter image description here






          share|improve this answer


























          • Thank you very much for your comment. It works nice, but I have one more question. How do we refer to a non framed definition or proposition etc? Normally with "label{}"?

            – Chris
            Feb 13 at 21:36






          • 1





            @Chris Do you mean a definition created by a newtheorem or by a newtcbtheorem ?

            – Hafid Boukhoulda
            Feb 13 at 21:42













          • From newtheorem :)

            – Chris
            Feb 13 at 21:42






          • 1





            @Chris label{mylabel} then ref{mylabel} where mylabel can be replaced with something like def:commutative ring

            – Hafid Boukhoulda
            Feb 13 at 21:51








          • 1





            @Chris answer updated

            – Hafid Boukhoulda
            Feb 13 at 22:41











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f474757%2fconsecutive-numbering-and-labels-in-tcolorbox%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5















          1. The tcbtheorem environments allow you to use counters from other tcbtheorems as well as existing LaTeX counters. It will be easier to define the standard LaTeX theorems first (all sharing the same counter), and then define the tcbtheorems (using that same counter).

          2. The problem is that a label for a tcbtheorem environment needs to be passed as an option to that environment in order for it to work correctly. This is not standard LaTeX behaviour (you would have noticed that labelling and referencing your definition environment would have worked without a hitch).


          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}
          % Define amsthm theorems first
          newtheorem{defin}{Definition}[section] % Creates a new counter, number within section
          newtheorem{prt}[defin]{Remark} % Putting [defin] in second position uses defin's counter instead of creating a new one
          newtheorem{prts}[defin]{Remarks} % Again share defin's counter
          newtheorem{exmp}[defin]{Example} % etc.
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          tcbuselibrary{theorems}
          % use counter*=defin to make each tcbtheorem share defin's counter
          newtcbtheorem[use counter*=defin, number within=section]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mypor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}
          renewcommand{rmdefault}{udidot}
          begin{document}
          chapter{Maximal and Prime Ideals}
          section{Maximal Ideals}
          % Normal labelling
          begin{defin} label{first_def}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}
          % tcbtheorem labelling
          begin{myprop}[label=prop:maximal]{Maximal Ideals Criterion}{}
          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}
          From the Proposition ref{prop:maximal} and definition ref{first_def}ldots
          end{document}


          Output:



          output



          As an aside, I would recommend using the cleveref package which can easily be set-up with the each tcbtheorem so as to produce a named reference instead of just a number e.g. 'proposition 1.1.2' vs '1.1.2'. That way you don't have to worry about whether you're referencing a theorem, or a definition, or a proposition etc. each time.



          FYI There was a rogue makeatletter in your code.






          share|improve this answer


























          • Works perfect, thank you. But, why makeatletter is a rogue?

            – Chris
            Feb 13 at 22:08






          • 1





            It wasn't doing anything. In general makeatletter should only be used 'temporarily', being following shortly by makeatother.

            – Pippip19
            Feb 14 at 6:38











          • Ok, thank you very much!

            – Chris
            Feb 15 at 20:56
















          5















          1. The tcbtheorem environments allow you to use counters from other tcbtheorems as well as existing LaTeX counters. It will be easier to define the standard LaTeX theorems first (all sharing the same counter), and then define the tcbtheorems (using that same counter).

          2. The problem is that a label for a tcbtheorem environment needs to be passed as an option to that environment in order for it to work correctly. This is not standard LaTeX behaviour (you would have noticed that labelling and referencing your definition environment would have worked without a hitch).


          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}
          % Define amsthm theorems first
          newtheorem{defin}{Definition}[section] % Creates a new counter, number within section
          newtheorem{prt}[defin]{Remark} % Putting [defin] in second position uses defin's counter instead of creating a new one
          newtheorem{prts}[defin]{Remarks} % Again share defin's counter
          newtheorem{exmp}[defin]{Example} % etc.
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          tcbuselibrary{theorems}
          % use counter*=defin to make each tcbtheorem share defin's counter
          newtcbtheorem[use counter*=defin, number within=section]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mypor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}
          renewcommand{rmdefault}{udidot}
          begin{document}
          chapter{Maximal and Prime Ideals}
          section{Maximal Ideals}
          % Normal labelling
          begin{defin} label{first_def}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}
          % tcbtheorem labelling
          begin{myprop}[label=prop:maximal]{Maximal Ideals Criterion}{}
          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}
          From the Proposition ref{prop:maximal} and definition ref{first_def}ldots
          end{document}


          Output:



          output



          As an aside, I would recommend using the cleveref package which can easily be set-up with the each tcbtheorem so as to produce a named reference instead of just a number e.g. 'proposition 1.1.2' vs '1.1.2'. That way you don't have to worry about whether you're referencing a theorem, or a definition, or a proposition etc. each time.



          FYI There was a rogue makeatletter in your code.






          share|improve this answer


























          • Works perfect, thank you. But, why makeatletter is a rogue?

            – Chris
            Feb 13 at 22:08






          • 1





            It wasn't doing anything. In general makeatletter should only be used 'temporarily', being following shortly by makeatother.

            – Pippip19
            Feb 14 at 6:38











          • Ok, thank you very much!

            – Chris
            Feb 15 at 20:56














          5












          5








          5








          1. The tcbtheorem environments allow you to use counters from other tcbtheorems as well as existing LaTeX counters. It will be easier to define the standard LaTeX theorems first (all sharing the same counter), and then define the tcbtheorems (using that same counter).

          2. The problem is that a label for a tcbtheorem environment needs to be passed as an option to that environment in order for it to work correctly. This is not standard LaTeX behaviour (you would have noticed that labelling and referencing your definition environment would have worked without a hitch).


          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}
          % Define amsthm theorems first
          newtheorem{defin}{Definition}[section] % Creates a new counter, number within section
          newtheorem{prt}[defin]{Remark} % Putting [defin] in second position uses defin's counter instead of creating a new one
          newtheorem{prts}[defin]{Remarks} % Again share defin's counter
          newtheorem{exmp}[defin]{Example} % etc.
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          tcbuselibrary{theorems}
          % use counter*=defin to make each tcbtheorem share defin's counter
          newtcbtheorem[use counter*=defin, number within=section]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mypor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}
          renewcommand{rmdefault}{udidot}
          begin{document}
          chapter{Maximal and Prime Ideals}
          section{Maximal Ideals}
          % Normal labelling
          begin{defin} label{first_def}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}
          % tcbtheorem labelling
          begin{myprop}[label=prop:maximal]{Maximal Ideals Criterion}{}
          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}
          From the Proposition ref{prop:maximal} and definition ref{first_def}ldots
          end{document}


          Output:



          output



          As an aside, I would recommend using the cleveref package which can easily be set-up with the each tcbtheorem so as to produce a named reference instead of just a number e.g. 'proposition 1.1.2' vs '1.1.2'. That way you don't have to worry about whether you're referencing a theorem, or a definition, or a proposition etc. each time.



          FYI There was a rogue makeatletter in your code.






          share|improve this answer
















          1. The tcbtheorem environments allow you to use counters from other tcbtheorems as well as existing LaTeX counters. It will be easier to define the standard LaTeX theorems first (all sharing the same counter), and then define the tcbtheorems (using that same counter).

          2. The problem is that a label for a tcbtheorem environment needs to be passed as an option to that environment in order for it to work correctly. This is not standard LaTeX behaviour (you would have noticed that labelling and referencing your definition environment would have worked without a hitch).


          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}
          % Define amsthm theorems first
          newtheorem{defin}{Definition}[section] % Creates a new counter, number within section
          newtheorem{prt}[defin]{Remark} % Putting [defin] in second position uses defin's counter instead of creating a new one
          newtheorem{prts}[defin]{Remarks} % Again share defin's counter
          newtheorem{exmp}[defin]{Example} % etc.
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          tcbuselibrary{theorems}
          % use counter*=defin to make each tcbtheorem share defin's counter
          newtcbtheorem[use counter*=defin, number within=section]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{mypor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}
          newtcbtheorem[use counter*=defin, number within=section]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}
          renewcommand{rmdefault}{udidot}
          begin{document}
          chapter{Maximal and Prime Ideals}
          section{Maximal Ideals}
          % Normal labelling
          begin{defin} label{first_def}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}
          % tcbtheorem labelling
          begin{myprop}[label=prop:maximal]{Maximal Ideals Criterion}{}
          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}
          From the Proposition ref{prop:maximal} and definition ref{first_def}ldots
          end{document}


          Output:



          output



          As an aside, I would recommend using the cleveref package which can easily be set-up with the each tcbtheorem so as to produce a named reference instead of just a number e.g. 'proposition 1.1.2' vs '1.1.2'. That way you don't have to worry about whether you're referencing a theorem, or a definition, or a proposition etc. each time.



          FYI There was a rogue makeatletter in your code.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 13 at 20:42

























          answered Feb 13 at 20:36









          Pippip19Pippip19

          1,2088




          1,2088













          • Works perfect, thank you. But, why makeatletter is a rogue?

            – Chris
            Feb 13 at 22:08






          • 1





            It wasn't doing anything. In general makeatletter should only be used 'temporarily', being following shortly by makeatother.

            – Pippip19
            Feb 14 at 6:38











          • Ok, thank you very much!

            – Chris
            Feb 15 at 20:56



















          • Works perfect, thank you. But, why makeatletter is a rogue?

            – Chris
            Feb 13 at 22:08






          • 1





            It wasn't doing anything. In general makeatletter should only be used 'temporarily', being following shortly by makeatother.

            – Pippip19
            Feb 14 at 6:38











          • Ok, thank you very much!

            – Chris
            Feb 15 at 20:56

















          Works perfect, thank you. But, why makeatletter is a rogue?

          – Chris
          Feb 13 at 22:08





          Works perfect, thank you. But, why makeatletter is a rogue?

          – Chris
          Feb 13 at 22:08




          1




          1





          It wasn't doing anything. In general makeatletter should only be used 'temporarily', being following shortly by makeatother.

          – Pippip19
          Feb 14 at 6:38





          It wasn't doing anything. In general makeatletter should only be used 'temporarily', being following shortly by makeatother.

          – Pippip19
          Feb 14 at 6:38













          Ok, thank you very much!

          – Chris
          Feb 15 at 20:56





          Ok, thank you very much!

          – Chris
          Feb 15 at 20:56











          4














          The key is the tcolorbox options use counter=<another counter> and use counter from= <counter from another tcolorbox>



          Update taking into account the OP comments:



          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}

          %makeatletter

          tcbuselibrary{theorems}

          newtcbtheorem[number within=section,use counter=defin]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter =defin]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter= defin]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{mycor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


          renewcommand{rmdefault}{udidot}

          begin{document}

          newtheorem{defin}{Definition}[section]
          newtheorem{prt}[defin]{Remark}
          newtheorem{prts}[defin]{Remarks}
          newtheorem{exmp}[defin]{Example}%[section]
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          chapter{Maximal and Prime Ideals}

          section{Maximal Ideals}

          begin{defin}
          label{def:commutative ring}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}

          begin{myprop}{Maximal Ideals Criterion}{Max Id Crit}

          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}

          From the Proposition ref{th:Max Id Crit},

          See definition ref{def:commutative ring}

          begin{exmp} label{ex: my example}
          my example
          end{exmp}

          example : ref{ex: my example}



          end{document}


          enter image description here






          share|improve this answer


























          • Thank you very much for your comment. It works nice, but I have one more question. How do we refer to a non framed definition or proposition etc? Normally with "label{}"?

            – Chris
            Feb 13 at 21:36






          • 1





            @Chris Do you mean a definition created by a newtheorem or by a newtcbtheorem ?

            – Hafid Boukhoulda
            Feb 13 at 21:42













          • From newtheorem :)

            – Chris
            Feb 13 at 21:42






          • 1





            @Chris label{mylabel} then ref{mylabel} where mylabel can be replaced with something like def:commutative ring

            – Hafid Boukhoulda
            Feb 13 at 21:51








          • 1





            @Chris answer updated

            – Hafid Boukhoulda
            Feb 13 at 22:41
















          4














          The key is the tcolorbox options use counter=<another counter> and use counter from= <counter from another tcolorbox>



          Update taking into account the OP comments:



          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}

          %makeatletter

          tcbuselibrary{theorems}

          newtcbtheorem[number within=section,use counter=defin]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter =defin]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter= defin]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{mycor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


          renewcommand{rmdefault}{udidot}

          begin{document}

          newtheorem{defin}{Definition}[section]
          newtheorem{prt}[defin]{Remark}
          newtheorem{prts}[defin]{Remarks}
          newtheorem{exmp}[defin]{Example}%[section]
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          chapter{Maximal and Prime Ideals}

          section{Maximal Ideals}

          begin{defin}
          label{def:commutative ring}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}

          begin{myprop}{Maximal Ideals Criterion}{Max Id Crit}

          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}

          From the Proposition ref{th:Max Id Crit},

          See definition ref{def:commutative ring}

          begin{exmp} label{ex: my example}
          my example
          end{exmp}

          example : ref{ex: my example}



          end{document}


          enter image description here






          share|improve this answer


























          • Thank you very much for your comment. It works nice, but I have one more question. How do we refer to a non framed definition or proposition etc? Normally with "label{}"?

            – Chris
            Feb 13 at 21:36






          • 1





            @Chris Do you mean a definition created by a newtheorem or by a newtcbtheorem ?

            – Hafid Boukhoulda
            Feb 13 at 21:42













          • From newtheorem :)

            – Chris
            Feb 13 at 21:42






          • 1





            @Chris label{mylabel} then ref{mylabel} where mylabel can be replaced with something like def:commutative ring

            – Hafid Boukhoulda
            Feb 13 at 21:51








          • 1





            @Chris answer updated

            – Hafid Boukhoulda
            Feb 13 at 22:41














          4












          4








          4







          The key is the tcolorbox options use counter=<another counter> and use counter from= <counter from another tcolorbox>



          Update taking into account the OP comments:



          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}

          %makeatletter

          tcbuselibrary{theorems}

          newtcbtheorem[number within=section,use counter=defin]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter =defin]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter= defin]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{mycor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


          renewcommand{rmdefault}{udidot}

          begin{document}

          newtheorem{defin}{Definition}[section]
          newtheorem{prt}[defin]{Remark}
          newtheorem{prts}[defin]{Remarks}
          newtheorem{exmp}[defin]{Example}%[section]
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          chapter{Maximal and Prime Ideals}

          section{Maximal Ideals}

          begin{defin}
          label{def:commutative ring}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}

          begin{myprop}{Maximal Ideals Criterion}{Max Id Crit}

          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}

          From the Proposition ref{th:Max Id Crit},

          See definition ref{def:commutative ring}

          begin{exmp} label{ex: my example}
          my example
          end{exmp}

          example : ref{ex: my example}



          end{document}


          enter image description here






          share|improve this answer















          The key is the tcolorbox options use counter=<another counter> and use counter from= <counter from another tcolorbox>



          Update taking into account the OP comments:



          documentclass[12pt,a4paper]{book}
          usepackage[utf8]{inputenc}
          usepackage{amsmath,amsthm,amsfonts,amssymb,mathtools}
          usepackage[english]{babel}
          usepackage{graphicx}
          usepackage{textcomp}
          usepackage{tcolorbox,xcolor}
          theoremstyle{definition}

          %makeatletter

          tcbuselibrary{theorems}

          newtcbtheorem[number within=section,use counter=defin]{mytheo}{Theorem}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter =defin]{myprop}{Proposition}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter= defin]{mylem}{Lemma}%
          {colback=black!5,colframe=red!50!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{mycor}{Corollary}%
          {colback=black!5,colframe=red!35!black,fonttitle=bfseries}{th}

          newtcbtheorem[number within=section,use counter=defin]{myax}{Axiom}%
          {colback=black!5,colframe=blue!35!black,fonttitle=bfseries}{th}


          renewcommand{rmdefault}{udidot}

          begin{document}

          newtheorem{defin}{Definition}[section]
          newtheorem{prt}[defin]{Remark}
          newtheorem{prts}[defin]{Remarks}
          newtheorem{exmp}[defin]{Example}%[section]
          newtheorem{exmps}[defin]{Examples}
          newtheorem*{note}{Note}

          chapter{Maximal and Prime Ideals}

          section{Maximal Ideals}

          begin{defin}
          label{def:commutative ring}
          Let $R$ a commutative ring with $1_R$ ...
          end{defin}

          begin{myprop}{Maximal Ideals Criterion}{Max Id Crit}

          Let $R$ a commutative ring with $1_R$ ...
          end{myprop}

          From the Proposition ref{th:Max Id Crit},

          See definition ref{def:commutative ring}

          begin{exmp} label{ex: my example}
          my example
          end{exmp}

          example : ref{ex: my example}



          end{document}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 13 at 22:38

























          answered Feb 13 at 20:33









          Hafid BoukhouldaHafid Boukhoulda

          3,7071622




          3,7071622













          • Thank you very much for your comment. It works nice, but I have one more question. How do we refer to a non framed definition or proposition etc? Normally with "label{}"?

            – Chris
            Feb 13 at 21:36






          • 1





            @Chris Do you mean a definition created by a newtheorem or by a newtcbtheorem ?

            – Hafid Boukhoulda
            Feb 13 at 21:42













          • From newtheorem :)

            – Chris
            Feb 13 at 21:42






          • 1





            @Chris label{mylabel} then ref{mylabel} where mylabel can be replaced with something like def:commutative ring

            – Hafid Boukhoulda
            Feb 13 at 21:51








          • 1





            @Chris answer updated

            – Hafid Boukhoulda
            Feb 13 at 22:41



















          • Thank you very much for your comment. It works nice, but I have one more question. How do we refer to a non framed definition or proposition etc? Normally with "label{}"?

            – Chris
            Feb 13 at 21:36






          • 1





            @Chris Do you mean a definition created by a newtheorem or by a newtcbtheorem ?

            – Hafid Boukhoulda
            Feb 13 at 21:42













          • From newtheorem :)

            – Chris
            Feb 13 at 21:42






          • 1





            @Chris label{mylabel} then ref{mylabel} where mylabel can be replaced with something like def:commutative ring

            – Hafid Boukhoulda
            Feb 13 at 21:51








          • 1





            @Chris answer updated

            – Hafid Boukhoulda
            Feb 13 at 22:41

















          Thank you very much for your comment. It works nice, but I have one more question. How do we refer to a non framed definition or proposition etc? Normally with "label{}"?

          – Chris
          Feb 13 at 21:36





          Thank you very much for your comment. It works nice, but I have one more question. How do we refer to a non framed definition or proposition etc? Normally with "label{}"?

          – Chris
          Feb 13 at 21:36




          1




          1





          @Chris Do you mean a definition created by a newtheorem or by a newtcbtheorem ?

          – Hafid Boukhoulda
          Feb 13 at 21:42







          @Chris Do you mean a definition created by a newtheorem or by a newtcbtheorem ?

          – Hafid Boukhoulda
          Feb 13 at 21:42















          From newtheorem :)

          – Chris
          Feb 13 at 21:42





          From newtheorem :)

          – Chris
          Feb 13 at 21:42




          1




          1





          @Chris label{mylabel} then ref{mylabel} where mylabel can be replaced with something like def:commutative ring

          – Hafid Boukhoulda
          Feb 13 at 21:51







          @Chris label{mylabel} then ref{mylabel} where mylabel can be replaced with something like def:commutative ring

          – Hafid Boukhoulda
          Feb 13 at 21:51






          1




          1





          @Chris answer updated

          – Hafid Boukhoulda
          Feb 13 at 22:41





          @Chris answer updated

          – Hafid Boukhoulda
          Feb 13 at 22:41


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f474757%2fconsecutive-numbering-and-labels-in-tcolorbox%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents