[Tex/LaTex] Environment with amsthm and tcolorbox – Attach boxed title to top

amsthmtcolorbox

I would like to use tcolorbox to create boxes for environments created with amsthm. MWE:

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{skins,theorems,breakable}
\usepackage{varwidth}

%Theorem with tcolorbox
\newtcbtheorem{YetAnotherTheorem}{Theorem}%
{enhanced,breakable,frame empty,interior empty,colframe=green!50!white,
coltitle=green!50!black,fonttitle=\bfseries,colbacktitle=green!15!white,
borderline={0.5mm}{0mm}{green!15!white},
borderline={0.5mm}{0mm}{green!50!white,dashed},
attach boxed title to top center={yshift=-2mm},
boxed title style={boxrule=0.4pt},varwidth boxed title}{theo}

%Theorem with amsthm
\newtheoremstyle{defstyle}
    {}
    {}
    {
    }
    {0pt}{}{}
    {\newline}
    {\ifx\relax#3\relax
   \textcolor{blue!50!white}{\textbf{#1} #2}%
 \else
   \textbf{#3}%
 \fi}
\theoremstyle{defstyle}
\newtheorem{definition}{Definition}
\tcolorboxenvironment{definition}{enhanced jigsaw,colframe=blue,colback=blue!20!white,breakable,before skip=10pt,after skip=10pt,attach boxed title to top center={yshift=-2mm}}

\begin{document}
\begin{YetAnotherTheorem}{Mittelwertsatz f\"{u}r $n$ Variable}{mittelwertsatz_n4}%
Es sei $n\in\mathbb{N}$, $D\subseteq\mathbb{R}^n$ eine offene Menge und
$f\in C^{1}(D,\mathbb{R})$. Dann gibt es auf jeder Strecke
$[x_0,x]\subset D$ einen Punkt $\xi\in[x_0,x]$, so dass gilt
\begin{align*}
f(x)-f(x_0) = \operatorname{grad} f(\xi)^{\top}(x-x_0)
\end{align*}
\end{YetAnotherTheorem}
\begin{definition}
Eine Funktion $f:~I\to\mathbb{R}$ auf einem Intervall $I$ hei\ss{}t in
$x_0\in I$ differenzierbar oder linear approximierbar,
wenn der Grenzwert
\begin{align*}
\lim\limits_{x\to x_0}\frac{f(x)-f(x_0)}{x-x_0}=\lim\limits_{h\to 0}\frac{f(x_0+h)-f(x_0)}{h}
\end{align*}
existiert. Bei Existenz hei\ss{}t dieser Grenzwert Ableitung
oder Differentialquotient von $f$ in $x_0$ und man
schreibt f\"{u}r ihn
\begin{align*}
f’(x_0)\quad\text{oder}\quad\frac{df}{dx}(x_0).
\end{align*}
\end{definition}
\end{document}

I worked with chapter 16.4 of the package documentation and I am almost happy with the result (once I use the correct colours anyway…), the only thing I am missing is the "attach boxed title". In the environment created with amsthm I have included a specific behaviour wether the definition/theorem has an optional name and I need that behaviour to be included.

  • How can I attach the title in a box when using the \tcolorboxenvirionment ?
    or
  • How can I include the mentioned behaviour in the \newtcbtheorem ?

When I added the code snippet used in the ams-theorem to the tcbtheorem, it resulted in error messages.

I posted this question already on the german community texwelt.de

Best Answer

  • Never mix ntheorem or amsthm and tcbtheorem. Rather use only one of them and separate their definitions.
  • If i understand you correctly, you look for something like this:

enter image description here

  • Title (text beside "Theorem" or "Definition") is obligatory field, so if you not like to have this text, leave it empty. for example: \begin{YetAnotherTheorem}{}{mittelwertsatz_n4}.

Above image is generated by:

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{many}
\usepackage{varwidth}

%Theorem with tcolorbox
\newtcbtheorem{YetAnotherTheorem}{Theorem}%
{
    enhanced jigsaw, breakable,
    frame empty, interior empty,
    colframe=green!50!white, coltitle=green!50!black,
    fonttitle=\bfseries,colbacktitle=green!15!white,
    borderline={1mm}{0mm}{green},
    attach boxed title to top center={yshift=-2mm},
    boxed title style={boxrule=0.4pt},
    varwidth boxed title
}{theo}

\newtcbtheorem{definition}{Definition}%
{
    enhanced jigsaw, breakable,
    colframe=blue,colback=blue!20!white,
    breakable,
    before skip=10pt,after skip=10pt,
    attach boxed title to top center={yshift=-2mm}
}{def}

\begin{document}
\begin{YetAnotherTheorem}{Mittelwertsatz f\"{u}r $n$ Variable}{mittelwertsatz_n4}
    Es sei $n\in\mathbb{N}$, $D\subseteq\mathbb{R}^n$ eine offene Menge und
    $f\in C^{1}(D,\mathbb{R})$. Dann gibt es auf jeder Strecke
    $[x_0,x]\subset D$ einen Punkt $\xi\in[x_0,x]$, so dass gilt
\[
f(x)-f(x_0) = \operatorname{grad} f(\xi)^{\top}(x-x_0)
\]
\end{YetAnotherTheorem}

\begin{YetAnotherTheorem}{}{mittelwertsatz_n4}
    Es sei $n\in\mathbb{N}$, $D\subseteq\mathbb{R}^n$ eine offene Menge und
    $f\in C^{1}(D,\mathbb{R})$. Dann gibt es auf jeder Strecke
    $[x_0,x]\subset D$ einen Punkt $\xi\in[x_0,x]$, so dass gilt
\[
f(x)-f(x_0) = \operatorname{grad} f(\xi)^{\top}(x-x_0)
\]
\end{YetAnotherTheorem}

\begin{definition}{}{important-definition}
    Eine Funktion $f:~I\to\mathbb{R}$ auf einem Intervall $I$ hei\ss{}t in $x_0\in I$ differenzierbar oder linear approximierbar, wenn der Grenzwert
\[
\lim\limits_{x\to x_0}\frac{f(x)-f(x_0)}{x-x_0}=\lim\limits_{h\to 0}\frac{f(x_0+h)-f(x_0)}{h}
\]
    existiert. Bei Existenz hei\ss{}t dieser Grenzwert Ableitung oder Differentialquotient von $f$ in $x_0$ und man schreibt f\"{u}r ihn
\[
f’(x_0)\quad\text{oder}\quad\frac{df}{dx}(x_0).
\]
\end{definition}
\end{document}
Related Question