2

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

| improve this question | | | | |
3
  • never mix ntheorem aor amsthm and tcbtheorem. use only one of it 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}
| improve this answer | | | | |
  • I don't use ntheorem but amsthm instead for which the author gives a tutorial on how to use other theorem environments with tcolorbox. I do want the design you have posted but I can't miss out on the specific behaviour of the title (not because I want it but our department wants it that way). So either I need a way to have the environment defined by amsthm and have it displayed with the extra box or create the environment with tcb and include the switch for the title. – Hirshy Sep 25 '17 at 14:58
  • sorry, than i can't help you further. – Zarko Sep 25 '17 at 15:14

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.