2

I'm trying to achieve the following result with tikz:

http://www.cpmtutor.com/c06/img/gif_26a.gif

but I'm not able to structure the nodes like those in figure. The colors and the arrow style are not important. It's just the node inner structure that I can't achieve.

EDIT: Here is what I tried to do:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\tikzstyle{activity}=[rectangle split,rectangle split parts=3,draw,text centered]

\begin{document}
\begin{tikzpicture}
\node[activity](A){row \nodepart{second} row \nodepart{third} row};
\end{tikzpicture}
\end{document}

but I haven't any idea on how to split the first and the third row.

  • You can put an entire tikzpicture inside a node. You could do a 3x3 matrix and overwrite the middle row, or do a 2x3 and put a node in the gap between them. – John Kormylo Jul 5 '15 at 16:42
  • It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem and shows that you made an effort. Also, there are several ways to achieve the above results, so if we had something to start with, a solution could be provided that is related to your code. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Jul 5 '15 at 17:17
5

Below I show two possibilities.

TikZ-free

Just using tabular and the picture environment:

enter image description here

The code:

\documentclass{article} 
\usepackage[table]{xcolor}
\usepackage{array}

\definecolor{mygray}{RGB}{231,236,240}
\definecolor{myorange}{RGB}{253,205,148}
\definecolor{myblue}{RGB}{107,146,201}

\newcommand\ActTable[7]{%
  \begingroup
  \sffamily
  \renewcommand\arraystretch{1.5}%
  \begin{tabular}{*{3}{|>{\centering\arraybackslash}p{0.5cm}}|}
  \hline
  \rowcolor{mygray} #2 & #3 & #4 \\
  \hline
  \rowcolor{mygray}\multicolumn{3}{|c|}{Activity #1} \\
  \hline
  \cellcolor{mygray}#5 & \cellcolor{myorange}\bfseries#6 & \cellcolor{mygray}#7 \\
  \hline
  \end{tabular}%
  \endgroup
}

\begin{document}

\begin{picture}(210,260)(0,-30)
% The left column
\put(0,200){\ActTable{A}{3}{4}{6}{7}{9}{8}}
\put(0,120){\ActTable{B}{5}{3}{2}{9}{1}{4}}
% The right column
\put(130,200){\ActTable{C}{1}{4}{8}{7}{9}{8}}
\put(130,120){\ActTable{D}{2}{2}{2}{2}{1}{4}}
\put(130,40){\ActTable{E}{3}{3}{3}{3}{3}{3}}
%% The arrrows 
\thicklines
\color{myblue}
\put(80,200){\vector(1,0){50}}
\put(80,190){\vector(1,-1){50}}
\put(80,120){\vector(1,0){50}}
\put(80,110){\vector(1,-1){50}}
\end{picture}

\end{document}

With TikZ

Instead of using a multipart \node, or a TikZ matrix or any other TikZ construct for the tabular material, I defined a command based on tabular; this has the advantage of avoiding nesting tikzpictures. Each tabular is placed using a \node and then the arrows are drawn using the node names.

enter image description here

The code:

\documentclass{article} 
\usepackage[table]{xcolor}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{positioning}

\definecolor{mygray}{RGB}{231,236,240}
\definecolor{myorange}{RGB}{253,205,148}
\definecolor{myblue}{RGB}{107,146,201}

\newcommand\ActTable[7]{%
  \begingroup
  \sffamily
  \renewcommand\arraystretch{1.5}%
  \begin{tabular}{*{3}{|>{\centering\arraybackslash}p{0.5cm}}|}
  \hline
  \rowcolor{mygray} #2 & #3 & #4 \\
  \hline
  \rowcolor{mygray}\multicolumn{3}{|c|}{Activity #1} \\
  \hline
  \cellcolor{mygray}#5 & \cellcolor{myorange}\bfseries#6 & \cellcolor{mygray}#7 \\
  \hline
  \end{tabular}%
  \endgroup
}

\begin{document}

\begin{tikzpicture}[
  node distance=0.5cm and 1.5cm,
  mynode/.style={inner sep=0pt},
  arro/.style={->,>=latex,myblue,thick}
]
% The column to the left
\node[mynode] (ul)
  {\ActTable{A}{3}{4}{6}{7}{9}{8}};
\node[mynode,below=of ul] (ml)
  {\ActTable{B}{5}{3}{2}{9}{1}{4}};
% The right column
\node[mynode,right=of ul] (ur)
  {\ActTable{C}{1}{4}{8}{7}{9}{8}};
\node[mynode,below=of ur] (mr)
  {\ActTable{D}{2}{2}{2}{2}{1}{4}};
\node[mynode,below=of mr] (lr)
  {\ActTable{E}{3}{3}{3}{3}{3}{3}};
% The arrrows 
\draw[arro] 
  (ul) -- (ur);
\draw[arro] 
   (ul.-10) -- ([yshift=5pt]mr.west);
\draw[arro] 
   (ml) -- (mr);
\draw[arro] 
   (ml.-10) -- ([yshift=5pt]lr.west);
\end{tikzpicture}

\end{document}

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.