
Kann ich mit Tikz ein Notizfeld im UML-Stil zeichnen?
Das folgende Bild wurde von UML kopiert:
Ich versuche es mit Tikz wie folgt:
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning,shapes.multipart}
\definecolor{activityBackgroundColor}{RGB}{254,254,206}
\definecolor{activityBorderColor}{RGB}{168,0,54}
\definecolor{noteBackgroundColor}{RGB}{251,251,119}
\definecolor{noteBorderColor}{RGB}{168,0,54}
\begin{document}
\begin{tikzpicture}[every text node part/.style={align=center}]
\node (A) [draw=activityBorderColor,fill=activityBackgroundColor,rectangle,rounded corners,] {Hello \\ world};
\node[draw=noteBorderColor,fill=noteBackgroundColor,rectangle,right=2mm of A] {this is \\ a node};
\end{tikzpicture}
\end{document}
Ausgabe:
Wie können wir genau den gleichen Stil wie das UML-Notizfeld erhalten?
Antwort1
Es gibt eine shapes.callout
Bibliothek, die ohne viel Arbeit dem nahe kommt. Wenn Sie auf dem Aussehen mit gefalteten Ecken bestehen, können Sie selbst eine neue Form erstellen (obwohl ich vermute, dass dieses eine Detail ziemlich viel Arbeit erfordert).
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning,shapes.multipart,shapes.callouts}
\definecolor{activityBackgroundColor}{RGB}{254,254,206}
\definecolor{activityBorderColor}{RGB}{168,0,54}
\definecolor{noteBackgroundColor}{RGB}{251,251,119}
\definecolor{noteBorderColor}{RGB}{168,0,54}
\begin{document}
\begin{tikzpicture}[every text node part/.style={align=center}]
\node (A) [draw=activityBorderColor,fill=activityBackgroundColor,rectangle,rounded corners,] {Hello \\ world};
\node[draw=noteBorderColor,fill=noteBackgroundColor,rectangle callout,callout relative pointer={(-1,0)},right =of A] {this is \\ a node};
\end{tikzpicture}
\end{document}
Antwort2
Wenn Sie die gefaltete kleine Ecke zu Alan Munns Antwort hinzufügen möchten:
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning,%shapes.multipart,
shapes.callouts}
\definecolor{activityBackgroundColor}{RGB}{254,254,206}
\definecolor{activityBorderColor}{RGB}{168,0,54}
\definecolor{noteBackgroundColor}{RGB}{251,251,119}
\definecolor{noteBorderColor}{RGB}{168,0,54}
\begin{document}
\begin{tikzpicture}[every text node part/.style={align=center}]
\node (A) [draw=activityBorderColor,fill=activityBackgroundColor,rectangle,rounded corners] {Hello \\ world};
\node[draw=noteBorderColor,fill=noteBackgroundColor,rectangle callout,callout relative pointer={(-1,0)},right =3em of A] (B) {this is \\ a node};
\draw[white, fill=white] ([xshift=-4pt]B.north east) -- (B.north east) -- ([yshift=-4pt]B.north east);
\draw[noteBorderColor, fill=noteBackgroundColor, line width=.4pt] ([shift={(-4pt,-.2pt)}]B.north east) -- ([shift={(-4pt,-4pt)}]B.north east) [rounded corners=.01pt]-- ([shift={(-.2pt,-4pt)}]B.north east) -- cycle;
\end{tikzpicture}
\end{document}