3

I'm wondering how could I draw node that looks like ** UML comment **. Any suggestions?

enter image description here

2
  • 2
    The PGF manual contains an example for creating exactly this node shape in the section "Declaring New Shapes".
    – Jake
    Dec 27, 2012 at 20:16
  • If you want to create UML diagrams with tikz, you should look at TikZ-UML. Dec 27, 2012 at 22:14

3 Answers 3

6

As it is stated in the tikz manual, there is no UML support in TikZ at the moment [p. 791]. So you might find MetaUML interesting, and especially their notes.

If you have installed MetaUML, simply save the following code as name.mp and type in the console mptopdf name.mp:

input metauml;
input TEX;

beginfig(5);
  Note.A("This class implements the formula:", 
          TEX("$\sum_1^n f(x)\cdot dx$"));
  drawObjects(A);
endfig;

end

You'll get this result as name.pdf.

Example of a Note in MetaUML

So you have to define your UML structure externally and then just include the pdf in your document.

Have Fun!

2
  • 1
    that's not what i want, it it is not how to do it in tikz
    – Meter
    Dec 27, 2012 at 20:13
  • @Daniel Thanks for the advise, I hope my answer is now more helpful.
    – rtzll
    Dec 28, 2012 at 13:47
2

Based on Meter reply, have created umlnote.sty

\ProvidesPackage{umlnote}

\usepackage{pgf,tikz}
\usetikzlibrary{calc,arrows}
    
\pgfdeclareshape{umlnote} {
    \inheritsavedanchors[from=rectangle]
    \inheritanchorborder[from=rectangle]
    \inheritanchor[from=rectangle]{center}
    \inheritanchor[from=rectangle]{north}
    \inheritanchor[from=rectangle]{north east}
    \inheritanchor[from=rectangle]{north west}
    \inheritanchor[from=rectangle]{south}
    \inheritanchor[from=rectangle]{south east}
    \inheritanchor[from=rectangle]{south west}
    \inheritanchor[from=rectangle]{west}
    \inheritanchor[from=rectangle]{east}
    \backgroundpath{
        \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
        \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
        \pgf@xc=\pgf@xb \advance\pgf@xc by-5pt
        \pgf@yc=\pgf@yb \advance\pgf@yc by-5pt
        \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
        \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
        \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
        \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
        \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
        \pgfpathclose
        \pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
        \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
        \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
        \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
    }
}

% Key to add font macros to the current font
\tikzset{add font/.code={\expandafter\def\expandafter\tikz@textfont\expandafter{\tikz@textfont#1}}} 

% Define default style for this node
\tikzset{umlnote/port labels/.style={font=\sffamily}}
\tikzset{every umlnote node/.style={draw, inner sep=2mm, outer sep=0pt,font=\scriptsize}}

use as

\usepackage{umlnote}
... in document
\begin{tikzpicture}
  \node[umlnote,minimum width=2cm, text width=2cm] at (0,0) (note1) {This some uml comment blah blah blah...};
\end{tikzpicture}

The result

umlnote example

0
\pgfdeclareshape{umlnote}
    {
        \inheritsavedanchors[from=rectangle]
        \inheritanchorborder[from=rectangle]
        \inheritanchor[from=rectangle]{center}
        \inheritanchor[from=rectangle]{north}
        \inheritanchor[from=rectangle]{north east}
        \inheritanchor[from=rectangle]{north west}
        \inheritanchor[from=rectangle]{south}
        \inheritanchor[from=rectangle]{south east}
        \inheritanchor[from=rectangle]{south west}
        \inheritanchor[from=rectangle]{west}
        \inheritanchor[from=rectangle]{east}
        \backgroundpath{
            \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
            \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
            \pgf@xc=\pgf@xb \advance\pgf@xc by-5pt
            \pgf@yc=\pgf@yb \advance\pgf@yc by-5pt
            \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
            \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
            \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
            \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
            \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
            \pgfpathclose
            \pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
            \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
            \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
            \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
        }
    }

copied from documentation

3
  • Does it work? If so could you post a working example, because solely \usepackage{tikz} and the shapes library are not enough to make this work.
    – rtzll
    Dec 27, 2012 at 22:51
  • 4
    You should consider improving your answer. First of all because it doesn't provide a minimal working example. Second because it doesn't provide any insight into how it solves your problem. Anybody else who hasn't read the pgf manual would not be able to make sense out of this.
    – user10274
    Dec 28, 2012 at 6:55
  • please don't downvote own answers.
    – percusse
    Dec 29, 2012 at 3:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .