[Tex/LaTex] Theorem statement in the title frame of an mdframed environment

mdframedtheorems

I've defined a theorem environment using the package mdframed. However, I'd like the statement to be contained within a different box from the one which contains the proof.

Ideally, this would be the title frame. However, if I try to put more than one line of text inside it, the text just goes on horizontally, ignoring even \\.

I've searched for examples both in the documentation of the package and online and I haven't found any that match what I want. Anyone knows if something like this can be done?

I provide here a minimal working example of my current environment:

Image of the result

\documentclass[11pt]{book}
\usepackage{amsthm}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}
\mdfsetup{skipabove=\topskip,skipbelow=\topskip}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%         Definition of the theorem environment         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{theo}[chapter]\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{chapter}.\arabic{theo}}

\makeatletter
\newenvironment{teorema}[1][]{%
\stepcounter{theo}\protected@edef\@currentlabel{\thetheo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,rounded corners,fill=Violet!20,draw= Violet!50, double= Violet!50]
{\strut Teorema~\thetheo};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,rounded corners,fill=Violet!20,draw= Violet!50, double=Violet!50]
{\strut Teorema~\thetheo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=Violet!50,backgroundcolor=Violet!5,%
linewidth=2pt,topline=true, 
frametitleaboveskip=\dimexpr-\ht\strutbox\relax,roundcorner=10pt}
\begin{mdframed}[]\relax%
\vspace{-0.25cm}}{\qed\end{mdframed}}
\makeatother

\begin{document}

\chapter{Sample Chapter}

\begin{teorema}[The theorem's statement]
Its proof
\end{teorema}

\end{document}

Best Answer

With tcolorbox most of the requests can be done out of the box. Most important is minipage boxed title=0.8\linewidth, for example.

\documentclass[11pt]{book}
\usepackage{amsthm}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}
\mdfsetup{skipabove=\topskip,skipbelow=\topskip}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%         Definition of the theorem environment         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{theo}[chapter]\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{chapter}.\arabic{theo}}

\makeatletter
\newenvironment{teorema}[1][]{%
\refstepcounter{theo}%
%\stepcounter{theo}\protected@edef\@currentlabel{\thetheo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,rounded corners,fill=Violet!20,draw= Violet!50, double= Violet!50]
{\strut Teorema~\thetheo};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,rounded corners,fill=Violet!20,draw= Violet!50, double=Violet!50]
{\strut Teorema~\thetheo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=Violet!50,backgroundcolor=Violet!5,%
linewidth=2pt,topline=true, 
frametitleaboveskip=\dimexpr-\ht\strutbox\relax,roundcorner=10pt}
\begin{mdframed}[]\relax%
\vspace{-0.25cm}}{\qed\end{mdframed}}
\makeatother

\usepackage[most]{tcolorbox}
\usepackage{blindtext}


\newtcbtheorem[auto counter,number within=chapter]{teoremaother}{Teorema}{%
  boxrule=2pt,
  enhanced,
  colback=Violet!5,
  colframe=Violet!50,
  colbacktitle=Violet!20,
  coltitle=black,
  fonttitle={\bfseries},
  minipage boxed title=0.8\linewidth,
  attach boxed title to top left={xshift=10pt,yshift*={-\tcboxedtitleheight/2}},
  boxed title style={parbox,boxrule=2pt},
  after upper={\qed},
}{th}

\begin{document}

\chapter{Sample Chapter}

\begin{teorema}[The theorem's statement which is a very long, long, long, long text]
Its proof
\end{teorema}

\begin{teoremaother}{The theorem's statement which is a very long, long, long, long text}{}
Its proof
\end{teoremaother}

\begin{teoremaother}{\blindtext}{}
Its proof
\end{teoremaother}


\end{document}

enter image description here