如何用角落有 TikZ 图片的矩形围绕定理/定义环境?

如何用角落有 TikZ 图片的矩形围绕定理/定义环境?

在另一个问题用户 campa显示如何使用 TikZ 绘制特定的图片(改编自布尔巴基危险弯道符号)。

我怎样才能在定理/定义/等环境周围绘制一个矩形,并在左上角显示 campa 的图片?

一个带有 TikZ 图片的框架定理

我希望能够使用类似以下的代码来实现这一点:

\documentclass{scrartcl}

\newtheorem{theorem}{Theorem}
\usepackage{lipsum}

\begin{document}

\begin{mydangerenv}[A]
\begin{theorem}
\lipsum[1]
\end{theorem}
\end{mydangerenv}

\end{document}

答案1

这是一个tcolorbox基于的尝试:

在此处输入图片描述

在此处输入图片描述

\documentclass{scrartcl}

\newtheorem{theorem}{Theorem}
\usepackage{lipsum}

\usepackage[most]{tcolorbox}
\usepackage{tikz}

% Definition of \mydangersymbol taken from: https://tex.stackexchange.com/a/604048/134144
\newcommand{\mydangersymbol}[1]{%
      \begin{tikzpicture}[baseline=(x.base)]
         \draw[rounded corners=.01em] (-.05em,-1.3em)rectangle(.05em,.9em);
         \draw[fill=white,rounded corners=1] (0,.8em)--(.8em,0)--(0,-.8em)--(-.8em,0)--cycle;
         \draw[very thick,line cap=round](-.3em,-1.3em)--(.3em,-1.3em);
         \node(x) at (0,0em) {\normalfont\sffamily\small#1};
      \end{tikzpicture}%
}


\NewTColorBox{mydangerenv}{+O{}}{%
    enhanced,
    sharp corners, 
    colback=white,
    coltitle=black,
    title={\mydangersymbol{#1}},
    attach boxed title to top left ={yshift=-\tcboxedtitleheight/2-4pt,
                                     yshifttext=-\tcboxedtitleheight/2-4pt, 
                                     xshift=-\tcboxedtitlewidth/2+0.25mm},
    boxed title style={colback=white,
                       colframe=white, 
                       sharp corners, 
                       boxsep=0pt, 
                       boxrule=0pt, 
                       bottom=3pt, 
                       halign title=flush center},
  boxrule=0.5mm,
  top=-\tcboxedtitleheight/2+5pt,
  boxsep=5pt,
  }

\begin{document}

\begin{mydangerenv}[A]
\begin{theorem}
\lipsum[1]
\end{theorem}
\end{mydangerenv}

\end{document}

相关内容