Here is a custom theorem environment that utilizes mdframed:
\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{ifthen}
%theorembox style
\mdfdefinestyle{theorembox}{%
leftmargin=2em,
rightmargin=2em,
innertopmargin=8pt,
innerbottommargin=8pt,
roundcorner=8pt,
backgroundcolor=gray!15
}
%theorem
\newenvironment{theorem}[1][]{%
\newcounter{thm}
\setcounter{thm}{1}
\newsavebox{\thmargbox}
\savebox{\thmargbox}{#1}
\begin{list}{}{%
\setlength{\leftmargin}{0pt}
\setlength{\rightmargin}{0pt}
}
\item
\begin{mdframed}[style=theorembox]
{\large Theorem \arabic{thm}\quad\ifthenelse{\wd\thmargbox=0}{}{#1\par}}%
}{%
\end{mdframed}
\end{list}
\stepcounter{thm}
}
\begin{document}
\begin{theorem}[First Theorem]
If $a\sim b$, then $b\sim a$.
\end{theorem}
%\begin{theorem}[Second Theorem]
% If $a\sim b$ and $b\sim c$, then $a\sim c$.
%\end{theorem}
\end{document}
However, if the second theorem is applied, the following error is reported:
! LaTeX Error: Command \c@thm already defined.
I think this may have more to do with my counter than mdframed, but any assistance would be appreciated.
\newcounter{thm}
outside the environment.thmargbox already defined
error persists.