1

I have a large document with theoreme-like environments based on \declaretheorem and references to them using \label and \cref.

I want to redefine those theorem-environments to be colored boxes based on tcolorbox.

Is there a simple solution without modifying the hole document?

Thank you very much.

\documentclass[11pt,a4paper,ngerman]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{amsthm}
\usepackage{thmtools}

\newtheoremstyle{break}{0pt}{0pt}{\normalfont}{0pt}{\bfseries}{}{\newline}{\thmname{#1} \thmnumber{#2} \quad \thmnote{\normalfont#3}}
\declaretheorem[style=break,name=Theorem]{theorem}

%% a colored Theorem style
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{cleveref}

\newtcbtheorem[
number within=chapter,
crefname={Theorem}{Theoreme},
]{theoremTCB}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}

%% want to replace 'theorem' to be the colored 'theoremTCB'
%% what to do with \label  ?
%\renewenvironment{theorem}[args][default]{begdef}{enddef}

\begin{document}
\chapter{Intro}
\begin{theorem}[Optional title]
\label{myfirstTheorem}
    blabla
\end{theorem}
this is the ref: -- \cref{myfirstTheorem} --. 

The Theorem shell be redefined to look like:

\begin{theoremTCB}{Hey}{marker}
    hello
\end{theoremTCB}
this is the ref: -- \cref{th:marker} --. 

\end{document}

1 Answer 1

1

amsthm and tcbtheorem cannot be used interchangeably, that means that your best shot to replace the one with the other is to use your editor's search and replace functionality (or sed or other nifty tricks in vim or emacs).

One thing you can do without changing our document, is using the skinning mechanism with \tcolorboxenvironment:

\documentclass[11pt,a4paper,ngerman]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{amsthm}
\usepackage{thmtools}

\newtheoremstyle{break}{0pt}{0pt}{\normalfont}{0pt}{\bfseries}{}{\newline}{\thmname{#1} \thmnumber{#2} \quad \thmnote{\normalfont#3}}
\declaretheorem[style=break,name=Theorem]{theorem}

%% a colored Theorem style
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{cleveref}

\newtcbtheorem[
number within=chapter,
crefname={Theorem}{Theoreme},
]{theoremTCB}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}

\tcolorboxenvironment{theorem}{ 
    breakable,
    colback=green!5,
    colframe={green!35!black},
}

%% want to replace 'theorem' to be the colored 'theoremTCB'
%% what to do with \label  ?
%\renewenvironment{theorem}[args][default]{begdef}{enddef}

\begin{document}
\chapter{Intro}
\begin{theorem}[Optional title]
\label{myfirstTheorem}
    blabla
\end{theorem}
this is the ref: -- \cref{myfirstTheorem} --. 

The Theorem shell be redefined to look like:

\begin{theoremTCB}{Hey}{marker}
    hello
\end{theoremTCB}
this is the ref: -- \cref{th:marker} --. 

\end{document}

enter image description here

2
  • @Tobias - You could make the border on top larger and change the color of the text to make it look more like theoremTCB, but right now I don't have the time to do it (also, I think it looks cleaner the way it is).
    – DG'
    Commented Dec 16, 2020 at 12:58
  • Thank you very much for your competent answer! It helps me a lot to know what is possible and what you would recommend.
    – Tobias
    Commented Dec 17, 2020 at 13:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .