4

Can I draw a uml style note box with tikz?

Below picture is copied from UML:

enter image description here

I try it with tikz as below:

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

Output:

enter image description here

How can we get exactly the same style as uml note box?

4

There is a shapes.callout library which comes close without much work. If you insist on the folded corner look, it's possible to create a new shape yourself (although quite a bit of work for that one detail, I suspect.)

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

output of code

4

If you would like to add the folded little corner to Alan Munn's answer:

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

enter image description here

  • Nice. It would be nice to make this a style such that the folded corner adapts to the direction of the callout pointer and also to the size of the callout rectangle. – Alan Munn Jul 13 '17 at 19:34
  • @AlanMunn Thank you! I'll try to improve it :) – CarLaTeX Jul 13 '17 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.