1

I need to create a node that is divided in three parts: a main part, the biggest, which holds the node id, and two equal sections that must go under it. These two subsections have the purpose of holding pointers. The reason I need it is for showing a tree structure with parents pointing to child node if the have any. Otherwise, the pointer is shown as null. For a better description, here is a picture of what I need: enter image description here

Thank you in advance!

4
  • Welcome to TeX.SX! Please show some own effort in trying to achieve what you want, and if you encounter problems while doing so, we'll gladly help. In it's current state your question is just "Do it for me", which is not what this site is there for.
    – Skillmon
    Dec 2, 2017 at 16:17
  • Ok. All I need is a way to divide a rectangular node in the parts shown in the image. I currently don't know how. I also ignore if it is possible to set a special type of node with specific divisions on its inside, which is my main doubt. Dec 2, 2017 at 16:28
  • This might help: tex.stackexchange.com/questions/88258/…
    – Skillmon
    Dec 2, 2017 at 16:33
  • One solution is to create a new shape. Another is to use a scope with [local bounding box=...], however only the standard boundary anchor points will be defined. You can use named coordinates for interior locations. Dec 2, 2017 at 16:58

1 Answer 1

3

There's a similar question here for circular nodes. You could in principle do this using the \nodeparts command (see section 17.3 of the manual), but I prefer to use a pic (see section 18.2).

Previously, I have defined pic's like this that take many arguments but below I have used \pgfkeys to write a key-value interface, with defaults, because this is much easier to use. The simplest use of the pic is something like

\draw (0,0) pic{splitSq};

to produce:

enter image description here

I have written pic{splitSq={key1=val1, key2=val2,...} to take the following key-value arguments:

  • size = the size of the rectangle in centimeters (default 1cm)
  • fill = the fill colour (default gray!10)
  • top = text in top region
  • left = text in lower left region
  • right = text in lower right region
  • name = tikz name for the node. This also defines names name-T, name-L and name-R for the top, left and right regions, respectively

Consequently, the code:

\begin{tikzpicture}
  \draw (6,0) pic{splitSq};
    \draw (0,0) pic{splitSq={top=T,left=L,right=R}};
    \draw (4,0) pic{splitSq={top=Hi, name=Hi}};
    \draw (3,2) pic{splitSq={left=/, fill=blue!10, name=Blue}};
    \draw (1,2) pic{splitSq={right=*, fill=green!10, name=Green}};
    \draw[->] (Green-R)--(Blue-L);
    \draw[->] (Hi)->(Blue);
\end{tikzpicture}

produces:

enter image description here

Here is the full MWE:

\documentclass{minimal}
\usepackage{tikz}
\begin{document}

\pgfkeys{/splitSq/.cd,
  size/.initial  = 1,            % size of square in centimeters
  size/.get      = \splitSqSize, %  store in macro \splitSqSize
  size/.store in = \splitSqSize,
  fill/.initial=gray!10,         % fill colour
  top/.initial=,                 % top text
  left/.initial=,                % left text
  right/.initial=,               % right text
  name/.initial  =,              % name
  name/.get      = \splitSqLabel,
  name/.store in = \splitSqLabel
}
\tikzset{
  pics/splitSq/.style args = {#1}{% #1=key-value pairs
    code = {
      \bgroup
        \pgfkeys{/splitSq/.cd, #1}% set key-value pairs
        \node (\splitSqLabel) at (0,0) [shape=rectangle,
                                        rounded corners,
                                        draw, inner sep=0pt,
                                        fill=\pgfkeysvalueof{/splitSq/fill},
                                        minimum size = \splitSqSize cm] {};
        \pgfmathsetmacro\quart{\splitSqSize/4}%
        \draw(-2*\quart,0)--++(\splitSqSize,0);%   and the lines
        \draw(0,0)--++(0,-2*\quart);
        \node(\splitSqLabel-L) at (-\quart,-\quart){\pgfkeysvalueof{/splitSq/left}};
        \node(\splitSqLabel-R) at (\quart,-\quart) {\pgfkeysvalueof{/splitSq/right}};
        \node(\splitSqLabel-T) at (0,\quart)       {\pgfkeysvalueof{/splitSq/top}};
     \egroup
    }
  }
}

\begin{tikzpicture}
    \draw (0,0) pic{splitSq={top=T,left=L,right=R}};
    \draw (4,0) pic{splitSq={top=Hi, name=Hi}};
    \draw (3,2) pic{splitSq={left=/, fill=blue!10, name=Blue}};
    \draw (1,2) pic{splitSq={right=*, fill=green!10, name=Green}};
    \draw[->] (Green-R)--(Blue-L);
    \draw[->] (Hi)->(Blue);
\end{tikzpicture}
\end{document}
0

You must log in to answer this question.

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