我不太清楚如何实现这一点,但我想制作一张类似于所附图片的图像。我想展示如何根据条件从一个表转换到另一个表。这个过程有正式名称吗?
答案1
使用 TikZ
您可以使用TikZ
借助以下方法构建每个矩阵matrix of math nodes
:
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,calc,positioning}
\tikzset{
common/.style={
text depth=1.25ex,
text height=2.5ex,
inner sep=0pt
},
table/.style={
matrix of math nodes,
common,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={rectangle,draw=black,text width=2em,align=center},
nodes in empty cells,
}
}
\newcommand\TabHead[4]{
\path
let
\p1=#1,
\p2=#2
in
node[
text width=\x2-\x1-2\pgflinewidth,
yshift=-\pgflinewidth,
align=center,
anchor=south,
draw,
fill=green!10,
common
]
at (#3.north)
{#4};
}
\newcommand\DrawArrow[2]{
\node (texto) at #1 {$\Rightarrow$};
\node[above=0pt of texto] {$\begin{array}{@{}c@{}}#2\end{array}$};
}
\begin{document}
\begin{tikzpicture}
\matrix (mat1) [table]
{
P & X & Y & Z \\
0 & 0 & 0 & 0 \\
1 & 0 & 0 & 1 \\
2 & 0 & 1 & 1 \\
3 & 1 & 1 & 1 \\
};
\TabHead{(mat1.west)}{(mat1.east)}{mat1}{Base Text}
\matrix (mat2) [table,right=2cm of mat1.north east,anchor=north west]
{
P & X & Y & Z \\
0 & 0 & 0 & 0 \\
1 & 0 & 0 & 1 \\
2 & 0 & 1 & 1 \\
};
\TabHead{(mat2.west)}{(mat2.east)}{mat2}{Other Text}
\matrix (mat3) [table,right=2cm of mat2.north east,anchor=north west]
{
P & X & Y & Z \\
0 & 0 & 0 & 0 \\
1 & 0 & 0 & 1 \\
2 & 0 & 1 & 1 \\
};
\TabHead{(mat3.west)}{(mat3.east)}{mat3}{Another Text}
\DrawArrow{($ (mat1.east)!0.5!(mat2.west) $)}{\Delta X \\ \Delta Y \\ \Delta Z}
\DrawArrow{($ (mat2.east)!0.5!(mat3.west) $)}{\Delta X \\ \Delta Y}
\end{tikzpicture}
\end{document}
不含 TikZ
您也可以不使用 TikZ 来执行此操作array
:
代码:
\documentclass{article}
\usepackage[table]{xcolor}
\newcommand\TableData[2]{%
{
\renewcommand\arraystretch{1.4}
$\begin{array}{@{}|c|c|c|c|@{}}
\hline\multicolumn{4}{|c|}{\cellcolor{green!10}\mbox{#2}} \\\hline#1\hline
\end{array}$%
}%
}
\newcommand\DrawArrow[1]{
$\begin{array}{@{}c@{}}
\begin{array}{c}
#1
\end{array} \\
\Rightarrow
\end{array}$%
}
\begin{document}
\begin{tabular}{ccccc}
\TableData{
P & X & Y & Z \\\hline
0 & 0 & 0 & 0 \\\hline
1 & 0 & 0 & 1 \\\hline
2 & 0 & 1 & 1 \\\hline
3 & 1 & 1 & 1 \\
}{Base Text}
&
\DrawArrow{\Delta X \\ \Delta Y \\ \Delta Z}
&
\TableData{
P & X & Y & Z \\\hline
0 & 0 & 0 & 0 \\\hline
1 & 0 & 0 & 1 \\\hline
2 & 0 & 1 & 1 \\
}{Other Text}
&
\DrawArrow{\Delta X \\ \Delta Y}
&
\TableData{
P & X & Y & Z \\\hline
0 & 0 & 0 & 0 \\\hline
1 & 0 & 0 & 1 \\\hline
2 & 0 & 1 & 1 \\
}{Another Text}
\end{tabular}
\end{document}