Fancy theorem boxes in LaTeX

December 14, 2023 (4mo ago)

We will make use of mdframed package.

\usepackage{mdframed,amsthm,tikz}

Setting the counter according to sections. Input this code in preamble.

\newcounter{theo}[section]\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{section}.\arabic{theo}}
\newenvironment{theo}[2][]{%
\refstepcounter{theo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!30]
{\strut Theorem~\thetheo};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!50]
{\strut Theorem~\thetheo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=blue!50,%
linewidth=1pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}

Now, the theorem box can be made by simply inserting

\begin{thetheo}

The statement of theorem

\end{thetheo}