不含 TikZ

不含 TikZ

我正在尝试使用 tikz 实现以下结果:

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

但我无法像图中那样构造节点。颜色和箭头样式并不重要。我只是无法实现节点内部结构。

编辑:这是我尝试做的:

\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}

但我不知道如何分割第一行和第三行。

答案1

下面我展示两种可能性。

不含 TikZ

仅使用tabularpicture环境:

在此处输入图片描述

代码:

\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}

使用 TikZ

我没有使用多部分\node、TikZ 矩阵或任何其他 TikZ 构造作为表格材料,而是定义了一个基于的命令tabular;这样做的好处是可以避免嵌套tikzpicture。每个tabular都使用 a 放置\node,然后使用节点名称绘制箭头。

在此处输入图片描述

代码:

\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}

相关内容