0

I was wondering if there is a way to number Theorems and Lemmas the following way:

  1. Theorems are numbered as [section number].[theorem number] (which I've already done), and
  2. Lemmas are numbered as [section number].[theorem number].[lemma number] (which I have not done).

For example, here's what I want: the first theorem in section 4 would be Theorem 4.1. If it has two lemmas, the second one should be Lemma 4.1.2. The first lemma following Theorem 4.2 should be Lemma 4.2.1.

Below is my current code. Any help wold be greatly appreciated!

\documentclass{article}
\usepackage{amsmath}
\usepackage{varwidth}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins}

%THEOREM
\newtcbtheorem[auto counter,number within=section]{theorem}{Theorem}%
{enhanced,frame empty,interior empty,colframe=cyan!50!white, top=8mm,
    coltitle=black,fonttitle=\bfseries,colbacktitle=cyan!15!white,
    borderline={0.5mm}{0mm}{cyan!15!white},
    borderline={0.5mm}{0mm}{cyan!50!white,dashed},
    attach boxed title to top left={yshift=-4mm},
    boxed title style={sharp corners=east,boxrule=1pt},varwidth boxed title}{thm}

%LEMMA
\newtcbtheorem[]{lemma}{Lemma}%
{enhanced,frame empty,interior empty,colframe=orange!75!white, top=8mm,
    coltitle=black,fonttitle=\bfseries,colbacktitle=orange!20!white,
    borderline={0.5mm}{0mm}{orange!20!white},
    borderline={0.5mm}{0mm}{orange!50!white,dashed},
    attach boxed title to top left={yshift=-4mm},
    boxed title style={sharp corners=east,boxrule=1pt},varwidth boxed title}{thm}

\begin{document}
    
    \section{First Section}
    
        \begin{theorem}{This one should be named Theorem 1.1}{}
            theorem
        \end{theorem}

        \begin{lemma}{This one should be named Lemma 1.1.1}{}
            lemma
        \end{lemma}
    
        \begin{lemma}{This one should be named Lemma 1.1.2}{}
            lemma
        \end{lemma}

\end{document}
1

This can be done by the number within = tcb@cnt@theorem.

\documentclass{article}
\usepackage{amsmath}
\usepackage{varwidth}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins}

\makeatletter

%THEOREM
\newtcbtheorem[auto counter,number within=section]{theorem}{Theorem}%
{enhanced,frame empty,interior empty,colframe=cyan!50!white, top=8mm,
    coltitle=black,fonttitle=\bfseries,colbacktitle=cyan!15!white,
    borderline={0.5mm}{0mm}{cyan!15!white},
    borderline={0.5mm}{0mm}{cyan!50!white,dashed},
    attach boxed title to top left={yshift=-4mm},
    boxed title style={sharp corners=east,boxrule=1pt},varwidth boxed title}{thm}

%LEMMA
\newtcbtheorem[number within = tcb@cnt@theorem]{lemma}{Lemma}%
{enhanced,frame empty,interior empty,colframe=orange!75!white, top=8mm,
    coltitle=black,fonttitle=\bfseries,colbacktitle=orange!20!white,
    borderline={0.5mm}{0mm}{orange!20!white},
    borderline={0.5mm}{0mm}{orange!50!white,dashed},
    attach boxed title to top left={yshift=-4mm},
    boxed title style={sharp corners=east,boxrule=1pt},varwidth boxed title}{thm}

\makeatother

\begin{document}
    
    \section{First Section}
    
        \begin{theorem}{This one should be named Theorem 1.1}{}
            theorem
        \end{theorem}

        \begin{lemma}{This one should be named Lemma 1.1.1}{}
            lemma
        \end{lemma}
    
        \begin{lemma}{This one should be named Lemma 1.1.2}{}
            lemma
        \end{lemma}

\end{document}

The result is like this:

result

8
  • Thank you so much!! I saw this weird thing on page 111 of this manual (texdoc.net/texmf-dist/doc/latex/tcolorbox/tcolorbox.pdf), but instead I tried \thetcbcounter and it didn't. Almost got there but missed it :) – Skorpion Nov 26 '20 at 8:25
  • @Skorpion Just a bit curious, since the lemmas shall appear before the theorem, would you consider add to the counter of lemma by 1? For example the lemma in front of Theorem 1.2 should be Lemma 1.2.1 instead of Lemma 1.1.1. – Jinwen Nov 26 '20 at 8:30
  • Just a side question (since StackExchange won't allow me to post another question in 40min), do you happen to know how to fix the conflict between labels of enumitem and tcolorbox? With this above preamble, if you type \begin{enumerate}[label=arabic*)] in one of the theorem environments, you'd get an error, but with [label=arabic*)] removed, it disappears. – Skorpion Nov 26 '20 at 8:31
  • Ahh, prior to switching to tcolorbox I've been using mdframed, and I enjoyed using nested boxes. So I would first present Theorem 1.2, but then in the proof below, I would say "we need the following lemma: \begin{lemma}. IMHO, it looks more aesthetically pleasing when there are nested boxes :) – Skorpion Nov 26 '20 at 8:35
  • @Skorpion I think this is a misspell, should be label=\arabic*). – Jinwen Nov 26 '20 at 8:39

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.