3

I want a result that looks like:

1 Section

Theorem 1.1

Corollary 1.1.1

Proposition 1.2

Corollary 1.2.1

...

This can be achieved easily using amsthm as I used to. However, I want to use tcolorbox for my new notes now but I just cannot find the command that allows me to put three numbers in the title. I searched around and the following is the best I get:

\documentclass{report}
\usepackage[most]{tcolorbox}

\usepackage{chngcntr}\counterwithout{section}{chapter}

\newcounter{theo}
\newtcbtheorem[number within=section]{theorem}{Theorem}{before title={\stepcounter{theo}}}{th}
\newtcbtheorem[number within=theo]{corollary}{Corollary}{}{cor}

\begin{document}
\section{testSection}
\begin{theorem}{testTitle}{}
test theorem
\end{theorem}
\begin{corollary}{testTitle}{}
test corollary
\end{corollary}
\end{document}

enter image description here

Thanks in advance for any help.

4
  • 2
    I believe you should add use counter=theo in the optional argument of the Theorem (and you can remove the \stepcounter): \newtcbtheorem[use counter=theo,number within=section]{theorem}{Theorem}{}{th}.
    – campa
    Aug 26, 2021 at 15:24
  • @campa That works! Thanks a lot!
    – Shana
    Aug 26, 2021 at 15:44
  • @campa Would you post your comment as an answer so I can accept it?
    – Shana
    Aug 26, 2021 at 16:08
  • Rather not. I never used tcolorbox in my life and I cannot really believe that it provides no way to access the real counter. Hopefully some expert will provide an answer.
    – campa
    Aug 26, 2021 at 16:10

1 Answer 1

2

The inner counter name has prefix tcb@cnt@ (check the example of key /tcb/new/auto counter in tcolorbox's user manual), hence with

\newtcbtheorem[number within=section]{theorem}{Theorem}{<options>}{th}

the theorem environment will use counter tcb@cnt@theorem. Therefore what you need is

\newtcbtheorem[number within=tcb@cnt@theorem]{corollary}{Corollary}{}{cor}

Full example

\documentclass{report}
\usepackage[most]{tcolorbox}

\usepackage{chngcntr}\counterwithout{section}{chapter}

\newtcbtheorem[number within=section]{theorem}{Theorem}{}{th}
\newtcbtheorem[number within=tcb@cnt@theorem]{corollary}{Corollary}{}{cor}

\begin{document}
\section{testSection}
\begin{theorem}{testTitle}{}
test theorem
\end{theorem}

\begin{corollary}{testTitle}{}
test corollary
\end{corollary}
\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.