tcolorbox 词干编号

tcolorbox 词干编号

我想知道是否有办法通过以下方式对定理和引理进行编号:

  1. 定理的编号为 [章节编号].[定理编号](我已经这样做了),并且
  2. 引理编号为 [章节编号].[定理编号].[引理编号](我没有这样做)。

例如,我想要的是:第 4 节中的第一个定理应该是定理 4.1。如果它有两个引理,第二个应该是引理 4.1.2。定理 4.2 之后的第一个引理应该是引理 4.2.1。

以下是我当前的代码。如能得到任何帮助我将不胜感激!

\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

这可以通过 来完成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}

结果是这样的:

结果

相关内容