Custom node in TikZ

Tikz pics are great for this sort of thing. They are described in great detail in section 18.2 of the tikz manual (version 3.0.1a).

For example, the code:

\documentclass{article}
\usepackage{tikz}

\tikzset{
  pics/mynode/.style args={#1,#2,#3}{
     code={
       \draw (0,0) -- (1,-1) -- (2,0) -- (2,2) -- (0,2) -- (0,0);
       \node[#3] (#1) at (1,1) {#2};
     }
  }
}

\begin{document}

  \begin{tikzpicture}
      \draw (0,0) pic{mynode={A, Hi, blue}};
      \draw (0,3) pic{mynode={B, Hello, red}};
      \draw (2,1.5) pic{mynode={C, Bye,}};
      \draw[thick, blue] (A)--(B)--(C)--(A);
  \end{tikzpicture}

\end{document}

produces the diagram:

enter image description here

I have defined your "custom node" as the pic mynode. It takes three arguments: the node label, node text and styling for the node (all three arguments must be given, but they can be left blank). The pic draws your custom shape and, as part of this, places a "real" node inside it, which can then we referred to using the node label as in the MWE.


Defining new node shapes isn't necessarily a basic question. But in this case you can cheat a bit by using the single arrow shape from the shapes.arrows library.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}

\tikzset{
  mycustomnode/.style={
    draw,
    single arrow,
    single arrow head extend=0,
    shape border uses incircle,
    shape border rotate=-90,
  }
}

\begin{document}
\begin{tikzpicture}
\node [mycustomnode] {};
\node [mycustomnode] at (2,0) {abc};
\end{tikzpicture}
\end{document}

TikZ has many predefined symbols. The one you're asking about is very similar to the signal symbol in the shapes.symbols library (section 67.4 in the documentation). A cloud symbol is also defined there.

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.symbols}
\begin{document}
\begin{tikzpicture}[
node distance = 3cm, auto,
block/.style={signal, draw, signal to=south}]
\node [block] (init) {initialize model};
\node [cloud,draw, left of=init] (expert) {expert};
\end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf