1

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}
  • Is there a reason for \stepcounter{theo}\protected@edef.... instead of using \refstepcounter{theo} ? – user31729 Mar 1 '18 at 23:26
  • Also, are you sticking to mdframed? – user31729 Mar 1 '18 at 23:27
  • Whoops, yes, there's a reason: ignorance! Thank you very much! As for wether I'm sticking with mdframed, not necessarily, I'm open to suggestions. @ChristianHupfer – Hercule Poirot Mar 1 '18 at 23:31
1

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

  • Wow, that's perfect! Thanks a lot! I didn't know tcolorbox was so powerful. I'll definitely switch to using it. – Hercule Poirot Mar 1 '18 at 23:54
  • @HerculePoirot: tcolorbox is a swiss knife package ;-) – user31729 Mar 1 '18 at 23:54
  • @HerculePoirot: One side note: the theorems made by tcolorbox have a 2nd mandatory argument meant for the label. Leave it empty if you don't need a label – user31729 Mar 1 '18 at 23:56
  • Perfect, I'll surely need that label argument. One last question, is there a way to prevent the indentation in every line after the first? Not sure if it's aesthetically a good choice, but just out of curiosity. – Hercule Poirot Mar 2 '18 at 0:02
  • @HerculePoirot: I have to investigate. – user31729 Mar 2 '18 at 0:10

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.