1

I would like to split the tikz shape.multipart node into 9 equal part for drawing PERT node/network. I could split into three rows but not columns. I want to split that into three columns with each compartment in same size.

enter image description here

 \documentclass[border=12pt]{standalone}
 \usepackage{tikz} 
 \usetikzlibrary{positioning,shadows,matrix,shapes.multipart}
 \pgfdeclarelayer{foreground}
 \pgfdeclarelayer{background}
 \pgfsetlayers{background,main,foreground}
 \makeatletter
 \def\tikz@extra@preaction#1{
{%
\pgfsys@beginscope%
  \setbox\tikz@figbox=\box\voidb@x%
  \begingroup\tikzset{#1}\expandafter\endgroup%
  \expandafter\def\expandafter\tikz@preaction@layer
  \expandafter{\tikz@preaction@layer}%
  \ifx\tikz@preaction@layer\pgfutil@empty%
  \path[#1];% do extra path
  \else%
  \begin{pgfonlayer}{\tikz@preaction@layer}%
  \path[#1];%
  \end{pgfonlayer}
  \fi%
  \pgfsyssoftpath@setcurrentpath\tikz@actions@path% restore
  \tikz@restorepathsize%
  \pgfsys@endscope%
  }%
 }
 \let\tikz@preaction@layer=\pgfutil@empty
 \tikzset{preaction layer/.store in=\tikz@preaction@layer}
 \makeatother

 \tikzset{
mp/.style = {
rectangle split,
rectangle split parts=3,
rectangle split part fill={#1}, 
% rectangle split horizontal,
% rectangle split parts=3,
draw, rounded corners, text width=2cm,
align=center, text=white,
preaction layer=background,       
drop shadow}
    }

\begin{document}
\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=1cm,thick]
\node (n1) [mp={red,blue,green}]
{
\nodepart[align=left]{one}  1  \\
    \nodepart[align=left]{two}  2 \\
\nodepart[align=left]{three}  3 
};
\end{tikzpicture}
\end{document}
1

I would not try to hack the multipart nodes further. Rather, it seems more natural to use a matrix. The styling can be done with a path picture.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{matrix,shadows.blur}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,column sep=-\pgflinewidth,row sep=-\pgflinewidth,
    inner sep=0pt,draw,very thick,rounded corners,blur shadow,
    path picture={
    \path (path picture bounding box.north west) coordinate(TL) --
     (path picture bounding box.south east)  coordinate(BR) 
     foreach \XX in {0,...,3} {coordinate[pos=\XX/3] (p\XX)};
     \foreach \XX [count=\YY] in {red,blue,green!70!black}
     {\fill[\XX,sharp corners] (TL|-p\the\numexpr\YY-1) rectangle (BR|-p\YY);} 
     \foreach \XX in {1,2}
     {\draw[thick] (TL|-p\XX) -- (BR|-p\XX) (TL-|p\XX) -- (BR-|p\XX); }},
    nodes={text width=2cm,minimum height=1cm,align=center,
     text=white,anchor=center,sharp corners,inner sep=2pt,thin}]
    { 1 & 2 & 3 \\
     1 & 2 & 3 \\
     1 & 2 & 3 \\};
\end{tikzpicture}
\end{document}

enter image description here

One can use the matrix node as a whole or the cells of the nodes just like other nodes to attach arrows etc.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{matrix,shadows.blur,positioning}
\begin{document}
\begin{tikzpicture}
 \matrix[matrix of nodes,column sep=-\pgflinewidth,row sep=-\pgflinewidth,
    inner sep=0pt,draw,very thick,rounded corners,blur shadow,
    path picture={
    \path (path picture bounding box.north west) coordinate(TL) --
     (path picture bounding box.south east)  coordinate(BR) 
     foreach \XX in {0,...,3} {coordinate[pos=\XX/3] (p\XX)};
     \foreach \XX [count=\YY] in {red,blue,green!70!black}
     {\fill[\XX,sharp corners] (TL|-p\the\numexpr\YY-1) rectangle (BR|-p\YY);} 
     \foreach \XX in {1,2}
     {\draw[thick] (TL|-p\XX) -- (BR|-p\XX) (TL-|p\XX) -- (BR-|p\XX); }},
    nodes={text width=2cm,minimum height=1cm,align=center,
     text=white,anchor=center,sharp corners,inner sep=2pt,thin}] (mat)
    { 1 & 2 & 3 \\
     1 & 2 & 3 \\
     1 & 2 & 3 \\};
 \node[right=2em of mat,draw,rounded corners,blur shadow,fill=red!20] (txt){Text};
 \node[below right=1ex and 2em of mat,draw,rounded corners,blur
 shadow,fill=blue!20] (txt2)
 {More Text};
 \draw[-stealth] (mat) -- (txt); 
 \draw[-stealth] (mat-1-3) -| (txt); 
 \draw[-stealth] (mat-3-2) |- (txt2); 
\end{tikzpicture}
\end{document}

enter image description here

3
  • Thank you @Schrödinger's cat, it works perfectly fine, but how do we connect this matrix to another matrix, like nodes? Please help me.
    – rakatex
    May 8 '20 at 19:20
  • 1
    @RameshKannan You can give the matrix a name like any other node, and connect it in the same way. I added an example.
    – user194703
    May 8 '20 at 19:29
  • That's wonderful. Thank you @ Schrödinger's cat for your kindness, support and time.
    – rakatex
    May 8 '20 at 19:48

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.