4

In another question user campa showed how to use TikZ to draw a certain picture (an adaptation of the Bourbaki dangerous bend symbol).

How can I draw a rectangle around a theorem/definition/etc. environment that has campa's picture at the top left corner?

A framed theorem with a TikZ picture in the corner

I'd like to be able to achieve this using code similar to the following:

\documentclass{scrartcl}

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

\begin{document}

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

\end{document}

Evan Aad
  • 11,066

1 Answers1

7

Here is a tcolorbox-based attempt:

enter image description here

enter image description here

\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; \drawvery thick,line cap=round--(.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}

leandriis
  • 62,593
  • Thanks. If I wish to tweak it a little so that the sign's right corner is aligned with the rectangle's top edge, how should I go about it? – Evan Aad Jul 11 '21 at 09:20
  • 2
    Play with the yshift values and the top= value. – SebGlav Jul 11 '21 at 09:33
  • 1
    @EvanAad: I've just updated my answer accordingly. The value of yshift was determined manually, so there may still be room for improvement. – leandriis Jul 11 '21 at 09:45