我可以用 tikz 绘制 uml 样式注释框吗?
下面的图片是从UML复制来的:
我使用 tikz 进行尝试,如下所示:
\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}
输出:
如何才能得到和uml注释框一模一样的风格呢?
答案1
有一个shapes.callout
图书馆不需要做太多工作就可以达到这个效果。如果你坚持要折角的外观,你可以自己创建一个新的形状(尽管我怀疑这个细节需要做很多工作。)
\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}
答案2
如果你想在 Alan Munn 的答案中添加折叠的小角:
\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}