# Definitions, theorems, … with description inside a box and the title above the box

I am searching for a definition (or similar) environment with the following features:

• Numbering
• Listing
• Definition title with number above the description
• Definition text inside a box with black border

It should look like the following example:

I tried to use amsthm and thmtools (which has \newframedtheorem, but titles get also framed) and like their numbering features but was not able to adjust the style.

• Since you have not accepted an answer yet: Do you miss something in the given answers? Apr 5, 2014 at 15:02
• I like the answers and I will accept one as soon as I win the fight with tcolorbox. The systems I am working with provide only tcolorbox 2.40 (or even older) which lack options required by your answer. I downloaded tcolorbox 2.80 and put it in a directory libs/tcolorbox. The problem is that tcolorbox includes its own tex files, so I have to copy them into the working directory (where the document's tex files are stored) or use the environment variable TEXINPUTS. I am searching for a solution without the environment variable and without throwing files into the working directory. Apr 5, 2014 at 18:25
• For a such a case, you can try an undocumented trick. Use \def\tcbpkgprefix{libs/tcolorbox/} before \usepackage[most]{libs/tcolorbox/tcolorbox}. Thus, the libraries are found without setting an environment variable. Apr 6, 2014 at 8:53

Something like that (based on tcolorbox)? You can remove the cleveref options, if you do not need or like them.

\documentclass{report}
\usepackage[most]{tcolorbox}

\usepackage{lipsum,cleveref}

\newtcbtheorem[auto counter,number within=chapter,
crefname={definition}{definitions},Crefname={Definition}{Definitions}% only for cleveref
]{mydef}{Definition}{%
enhanced,frame hidden,coltitle=black,fonttitle=\bfseries,
interior style={fill=none,draw=black,line width=0.6pt},
left=0mm,right=0mm,top=0mm,bottom=0mm,arc=0pt,outer arc=0pt,
terminator sign colon}{def}

\begin{document}
\chapter{First chapter}

See something in \Cref{def:AREF} or \Cref{def:BREF}.

\begin{mydef}{}{AREF}
\lipsum[1]
\end{mydef}

\begin{mydef}{}{BREF}
\lipsum[2]
\end{mydef}

\end{document}


The first example code aligned the box frames with the surrounding text. Alternatively, the boxed text could be aligned with the normal page content. The following code shows another implementation which may be nicer for breaking the boxes, if you should look for this. Finally, a list of definitions is given.

\documentclass{report}
\usepackage[most]{tcolorbox}

\usepackage{lipsum,cleveref}

\newtcbtheorem[auto counter,number within=chapter,list inside=mytheorems,
crefname={definition}{definitions},Crefname={Definition}{Definitions}% only for cleveref
]{mydef}{Definition}{%
enhanced jigsaw,breakable,oversize,interior hidden,colframe=black,
boxrule=0.6pt,left=0mm,right=0mm,top=0mm,bottom=0mm,arc=0pt,outer arc=0pt,boxsep=1mm,
terminator sign colon,description delimiters parenthesis,separator sign none,
detach title,coltitle=black,fonttitle=\bfseries,
enlarge top by=1.2\baselineskip,enlarge top at break by=0mm,pad at break=0mm,
overlay unbroken and first={\node[anchor=base west,inner sep=1mm,outer sep=0.6pt,yshift=4pt]
at (frame.north west) {\tcbtitle};},
}{def}

\begin{document}
\chapter{First chapter}

See something in \Cref{def:AREF}, \Cref{def:BREF} or \Cref{def:CREF}.

\begin{mydef}{My title}{AREF}
\lipsum[1]
\end{mydef}

\lipsum[2]

\begin{mydef}{}{BREF}
\lipsum[3]
\end{mydef}

\lipsum[4]

\begin{mydef}{Another one}{CREF}
\lipsum[5]
\end{mydef}

\tcblistof[\chapter]{mytheorems}{List of Definitions and Theorems}

\end{document}


UPDATE: Alternatively, the same output is achieved with the following more elegant code relying on tcolorbox v3.00 (2014/05/08):

\documentclass{report}
\usepackage[many]{tcolorbox}%  version 3.00 (2014/05/09) and above

\usepackage{lipsum,cleveref}

\newtcbtheorem[auto counter,number within=chapter,list inside=mytheorems,
crefname={definition}{definitions},Crefname={Definition}{Definitions}% only for cleveref
]{mydef}{Definition}{%
enhanced jigsaw,breakable,oversize,interior hidden,colframe=black,
terminator sign colon,description delimiters parenthesis,separator sign none,
attach boxed title to top left={yshift=-1mm},minipage boxed title,
boxed title style={empty,boxrule=0.6pt,left=0mm,right=0mm,top=0mm,bottom=0mm,boxsep=1mm},
coltitle=black,fonttitle=\bfseries,before title=\strut}{def}

\begin{document}
\chapter{First chapter}

See something in \Cref{def:AREF}, \Cref{def:BREF} or \Cref{def:CREF}.

\begin{mydef}{My title}{AREF}
\lipsum[1]
\end{mydef}

\lipsum[2]

\begin{mydef}{}{BREF}
\lipsum[3]
\end{mydef}

\lipsum[4]

\begin{mydef}{Another one}{CREF}
\lipsum[5]
\end{mydef}

\tcblistof[\chapter]{mytheorems}{List of Definitions and Theorems}

\end{document}


Another option, using mdframed this time:

\documentclass{report}
\usepackage{amsmath}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newcounter{defi}
\numberwithin{defi}{chapter}
\newmdenv[
settings={\refstepcounter{defi}},
singleextra={
\node[
overlay,
inner xsep=0pt,
anchor=south west,
font=\bfseries
] at ([xshift=5pt]O|-P) {Definition~\thedefi:};
},
firstextra={
\node[
overlay,
inner xsep=0pt,
anchor=south west,
font=\bfseries
] at ([xshift=5pt]O|-P) {Definition~\thedefi:};
},
skipabove=4.5ex,
innerleftmargin=5pt,
innerrightmargin=5pt,
leftmargin=-5pt,
rightmargin=-5pt,
]{mydef}

\begin{document}

\chapter{Test chapter}

\begin{mydef}
\lipsum[4]
\end{mydef}
\lipsum[4]
\begin{mydef}
\lipsum[2]
\end{mydef}

\end{document}