定义、定理等,描述在框内,标题在框上方

定义、定理等,描述在框内,标题在框上方

我正在寻找具有以下功能的定义(或类似)环境:

  • 编号
  • 清单
  • 定义标题及编号位于描述上方
  • 带有黑色边框的框内的定义文本

它应该看起来像下面的例子:

带标题的定义框

我尝试使用amsthmthmtools(具有\newframedtheorem,但标题也被框架)并且喜欢它们的编号功能,但无法调整样式。

答案1

类似的东西(基于)?如果您不需要或不喜欢这些选项,tcolorbox可以将其删除。cleveref

\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}

在此处输入图片描述

第一个示例代码将框与周围的文本对齐。或者,框中的文本可以与正常的页面内容对齐。以下代码显示了另一种实现,如果您需要的话,它可能更适合打破框。最后,给出了定义列表。

\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}

在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

更新: 或者,使用以下更优雅的代码来实现相同的输出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,
  boxrule=0.6pt,left=0mm,right=0mm,top=0mm,bottom=0mm,arc=0pt,outer arc=0pt,boxsep=1mm,pad at break=0pt,
  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}

答案2

另一种选择是使用mdframed这次:

\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}

在此处输入图片描述

相关内容