我期待创作以下插图:
我的代码:
%%% code replaced in the edit.
编辑:
根据@JohnKormylo 的回答,我修改了我的代码如下:
\documentclass{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}
\usepackage{physics}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[>=Stealth, node distance=1.cm]
% Row 1
\node (A) {
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{ } & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{..} & \multicolumn{1}{c}{\textit{m-1}} & \multicolumn{1}{c}{\textit{m}} \\
\cline{2-6}
0 & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
1 & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\textit{n-1} & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\textit{n} & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\end{tabular}
};
\node[right=of A] (B) {
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{..} & \multicolumn{1}{c}{\textit{m-1}} & \multicolumn{1}{c}{\textit{m}} \\
\cline{2-6}
0 & & \cellcolor{gray!75} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \cellcolor{gray!10} \\
\cline{2-6}
1 & \cellcolor{gray!40} & \cellcolor{gray!50} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \cellcolor{gray!75} \\
\cline{2-6}
. & \cellcolor{gray!25} & \cellcolor{gray!50} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \cellcolor{gray!50} \\
\cline{2-6}
\textit{n-1} & \cellcolor{gray!25} & \cellcolor{gray!25} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \cellcolor{gray!25} \\
\cline{2-6}
\textit{n} & & \cellcolor{gray!25} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{..} & \\
\cline{2-6}
\end{tabular}
};
\node[right=of B] (C) {
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{\textit{m}} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{..} & \multicolumn{1}{c}{\textit{m-1}} \\
\cline{2-6}
& \cellcolor{gray!100} & \cellcolor{gray!75} & \multicolumn{1}{c|}{ \cellcolor{gray!50} } & \multicolumn{1}{c|}{ \cellcolor{gray!25} } & \cellcolor{gray!10} \\
\cline{2-6}
\multicolumn{1}{c}{} & \multicolumn{4}{l}{ $ \underbrace{ \text{. . . . . . . . . . . } }_\textit{ Subspace } $ } & \multicolumn{1}{c}{}
\end{tabular}
};
%%% Row 2 %%%
\node [below=of A] (D){
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{1} &
\multicolumn{1}{c}{..} & \multicolumn{1}{c}{ \textit{m-1} } & \multicolumn{1}{c}{ \textit{ m } } \\
\cline{2-6}
0 & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
1 & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\textit{n-1} & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\textit{n} & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\end{tabular}
};
\node[right=of D](E){
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} &
\multicolumn{1}{c}{..} & \multicolumn{1}{c}{ \textit{m-1} } & \multicolumn{1}{c}{ \textit{ m } } \\
\cline{2-6}
0 & \cellcolor{gray!100} & & \multicolumn{1}{c|}{ ..} & \multicolumn{1}{c|}{ \cellcolor{gray!75}} & \\
\cline{2-6}
1 & \cellcolor{gray!25} & & \multicolumn{1}{c|}{ ..} & \multicolumn{1}{c|}{ \cellcolor{gray!50}} & \cellcolor{gray!25} \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ \cellcolor{gray!75} } & \\
\cline{2-6}
. & \cellcolor{gray!100} & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ \cellcolor{gray!75} } & \cellcolor{gray!50} \\
\cline{2-6}
\textit{n-1} & \cellcolor{gray!75} & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \cellcolor{gray!50} \\
\cline{2-6}
\textit{n} & \cellcolor{gray!50} & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ \cellcolor{gray!75} } & \\
\cline{2-6}
\end{tabular}
};
\node[right=of E](F){
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{ \textit{ m-1 } } &
\multicolumn{1}{c}{1} & \multicolumn{1}{c}{..} & \multicolumn{1}{c}{ \textit{ m } } \\
\cline{2-6}
& \cellcolor{gray!100} & \cellcolor{gray!75} & \multicolumn{1}{c|}{ \cellcolor{gray!50} } & \multicolumn{1}{c|}{ \cellcolor{gray!50} } & \cellcolor{gray!25} \\
\cline{2-6}
\multicolumn{1}{c}{} & \multicolumn{4}{l}{ $ \underbrace{ \text{. . . . . . . . . . . } }_\textit{ Subspace } $ } & \multicolumn{1}{c}{}
\end{tabular}
};
%%% Row 3 %%%%
\node[below=of D](G){
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{1} &
\multicolumn{1}{c}{..} & \multicolumn{1}{c}{ \textit{m-1} } & \multicolumn{1}{c}{ \textit{ m } } \\
\cline{2-6}
0 & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
1 & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
\textit{n-1} & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
\textit{n} & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\end{tabular}
};
\node[right=of G](H){
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{1} &
\multicolumn{1}{c}{ ..} & \multicolumn{1}{c}{ \textit{m-1} } & \multicolumn{1}{c}{ \textit{m} } \\
\cline{2-6}
0 & \cellcolor{gray!100} & \cellcolor{gray!75} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
1 & \cellcolor{gray!25} & \cellcolor{gray!75} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \cellcolor{gray!50} \\
\cline{2-6}
. & & \cellcolor{gray!25} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
. & \cellcolor{gray!100} & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \cellcolor{gray!25} \\
\cline{2-6}
\textit{n-1} & \cellcolor{gray!50} & \cellcolor{gray!50} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \cellcolor{gray!50} \\
\cline{2-6}
\textit{n} & \cellcolor{gray!50} & \cellcolor{gray!75} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\end{tabular}
};
\node[right=of H](I){
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{ \textit{ 1 } } &
\multicolumn{1}{c}{ \textit{ m } } & \multicolumn{1}{c}{} & \multicolumn{1}{c}{ \textit{ m-1 } } \\
\cline{2-6}
& \cellcolor{gray!100} & \cellcolor{gray!75} & \multicolumn{1}{c|}{ \cellcolor{gray!50} } & \multicolumn{1}{c|}{ \cellcolor{gray!25} } & \cellcolor{gray!10} \\
\cline{2-6}
\multicolumn{1}{c}{} & \multicolumn{4}{l}{ $ \underbrace{ \text{. . . . . . . . . . . } }_\textit{ Subspace } $ } & \multicolumn{1}{c}{}
\end{tabular}
};
% Captions
\node[above=0cm of A] {$ \phi_1(x_{i,j})$};
\node[above=0cm of B] {$ | \phi_1(x_{i,j}) | $};
\node[above=0cm of C] {$ \vb{x}_1 = \sum_{i=1}^{n} |\phi(x_{i,j})| $};
\node[above=0cm of D] {$ \phi_2(x_{i,j})$};
\node[above=0cm of E] {$ | \phi_2(x_{i,j}) | $};
\node[above=0cm of F] {$ \vb{x}_2 = \sum_{i=1}^{n} |\phi(x_{i,j})| $};
\node[above=0cm of G] {$ \phi_k(x_{i,j})$};
\node[above=0.cm of H] {$ | \phi_k(x_{i,j}) | $};
\node[above=0.cm of I] {$ \vb{x}_k = \sum_{i=1}^{n} |\phi(x_{i,j})| $};
% Below
\node[below=0.1cm of G]{First phase};
\node[below=0.1cm of H]{Second phase};
\node[below=0.1cm of I]{Third phase};
% Arrows for row 1
\draw [->] (A) edge (B) (B) edge (C);
\draw [->] (D) edge (E) (E) edge (F);
\draw [->] (G) edge (H) (H) edge (I);
\end{tikzpicture}
\caption{Process description here.}
\end{figure}
\end{document}
生产:
问题
我该如何修改它为:
- 使表格重叠
- 相应地,将标题调整到节点的两侧?
答案1
你可以使用 Ti钾Z 矩阵代替表格,这样可以简化定位,还可以解决单元格着色问题。由于您多次使用相同的矩阵,因此可以\pic
从中创建一个矩阵来简化代码(代码仍然很长)。在下面的例子中,我没有正确地为单元格着色,因为我只想向您展示基本方法:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, decorations.pathreplacing}
\tikzset{
tabular matrix/.style={
matrix of math nodes,
nodes in empty cells,
row sep =-\pgflinewidth,
column sep = -\pgflinewidth,
nodes={
font=\footnotesize,
minimum width=2.75em,
minimum height=1.5em,
inner sep=0pt,
anchor=center,
execute at end node=\strut,
draw,
fill=white
},
row 1/.style={
nodes={
draw=none
}
},
column 1/.style={
nodes={
draw=none
}
},
},
pics/tabular/.style={
code={
\matrix[tabular matrix, ampersand replacement=\&, #1] (-m) {
\& 0 \& 1 \& \cdots \& m-1 \& m \\
0 \& \& \& \cdots \& \& \\
1 \& \& \& \cdots \& \& \\
\cdot \& \cdot \& \cdot \& \cdot \& \cdot \& \cdot \\
\cdot \& \cdot \& \cdot \& \cdot \& \cdot \& \cdot \\
n-1 \& \& \& \cdots \& \& \\
n \& \& \& \cdots \& \& \\
};
}
}
}
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,2,3} {
\pic (a-\i) at ({\i*1.25},{\i*-2.5}) {tabular};
\node[anchor=east] at ([yshift=-0.5cm]a-\i-m.west) {$\varphi_{
\ifnum\i=3\relax k\else3\fi
}(x_{i,j})$};
}
\pic at ([xshift=6cm]a-1-m.east) (b-1) {tabular={
row 2 column 3/.style={nodes={fill=gray!75}},
row 3 column 3/.style={nodes={fill=gray!40}},
row 4 column 3/.style={nodes={fill=gray!25}}
}};
\draw[-stealth] (a-1-m.east) -- (b-1-m.west);
\node[anchor=east] at ([yshift=-0.5cm]b-1-m.west)
{$|\varphi_{1}(x_{i,j})|$};
\pic at ([xshift=6cm]a-2-m.east) (b-2) {tabular={
row 2 column 3/.style={nodes={fill=gray!75}},
row 3 column 3/.style={nodes={fill=gray!40}},
row 4 column 3/.style={nodes={fill=gray!25}}
}};
\draw[-stealth] (a-2-m.east) -- (b-2-m.west);
\node[anchor=east] at ([yshift=-0.5cm]b-2-m.west)
{$|\varphi_{2}(x_{i,j})|$};
\pic at ([xshift=6cm]a-3-m.east) (b-3) {tabular={
row 2 column 3/.style={nodes={fill=gray!75}},
row 3 column 3/.style={nodes={fill=gray!40}},
row 4 column 3/.style={nodes={fill=gray!25}}
}};
\draw[-stealth] (a-3-m.east) -- (b-3-m.west);
\node[anchor=east] at ([yshift=-0.5cm]b-3-m.west)
{$|\varphi_{k}(x_{i,j})|$};
\matrix[tabular matrix, column 1/.style={nodes=draw},
row 2 column 1/.style={nodes={fill=gray!75}},
row 2 column 2/.style={nodes={fill=gray!40}},
row 2 column 3/.style={nodes={fill=gray!25}}
] (c-1-m) at ([shift={(6cm, 0.75em)}]b-1-m.east) {
1 & m & 0 & & \cdots & m-1 \\
& & & & & \\
};
\draw[decorate, decoration=brace]
([yshift=-2pt]c-1-m-2-5.south east) -- ([yshift=-2pt]c-1-m-2-1.south west)
node[below, midway] {subspace};
\draw[-stealth] (b-1-m.east) -- (b-1-m.east -| c-1-m.west);
\node[anchor=east] at ([yshift=0.25cm]c-1-m.north)
{$x_{1} = \sum_{i=1}^{n} |\varphi_{1}(x_{i,j})| \geq \rho$};
\matrix[tabular matrix, column 1/.style={nodes=draw},
row 2 column 1/.style={nodes={fill=gray!75}},
row 2 column 2/.style={nodes={fill=gray!40}},
row 2 column 3/.style={nodes={fill=gray!25}}
] (c-2-m) at ([shift={(6cm, 0.75em)}]b-2-m.east) {
0 & m-1 & 1 & & \cdots & m \\
& & & & & \\
};
\draw[decorate, decoration=brace]
([yshift=-2pt]c-2-m-2-4.south east) -- ([yshift=-2pt]c-2-m-2-1.south west)
node[below, midway] {subspace};
\draw[-stealth] (b-2-m.east) -- (b-2-m.east -| c-2-m.west);
\node[anchor=east] at ([yshift=0.25cm]c-2-m.north)
{$x_{2} = \sum_{i=1}^{n} |\varphi_{2}(x_{i,j})| \geq \rho$};
\matrix[tabular matrix, column 1/.style={nodes=draw},
row 2 column 1/.style={nodes={fill=gray!75}},
row 2 column 2/.style={nodes={fill=gray!40}},
row 2 column 3/.style={nodes={fill=gray!25}}
] (c-3-m) at ([shift={(6cm, 0.75em)}]b-3-m.east) {
0 & 1 & m & & \cdots & m-1 \\
& & & & & \\
};
\draw[decorate, decoration=brace]
([yshift=-2pt]c-3-m-2-5.south east) -- ([yshift=-2pt]c-3-m-2-1.south west)
node[below, midway] {subspace};
\draw[-stealth] (b-3-m.east) -- (b-3-m.east -| c-3-m.west);
\node[anchor=east] at ([yshift=0.25cm]c-3-m.north)
{$x_{k} = \sum_{i=1}^{n} |\varphi_{k}(x_{i,j})| \geq \rho$};
\node at (0,-10 -| a-1-m) {a.) First phase};
\node at (0,-10 -| b-1-m) {b.) Second phase};
\node at (0,-10 -| c-1-m) {c.) Third phase};
\end{tikzpicture}
\end{document}
答案2
这应该能让你开始使用 tikzpicture。但是,彩色表格不是我的专长,但我知道使用 xcolor 时经常会丢失线条。有专门处理此问题的软件包(如 tabulararray),但你可能不得不使用 savebox,因为你无法将 tikzpicture 放在 tikzpicture 中。
\documentclass[12pt]{article}
\usepackage[table]{xcolor}
\usepackage{subcaption}
\usepackage[margin=1.5cm]{geometry}
\usepackage{mathtools}
\usepackage{tikz}
\begin{document}
\section{Illustration}
\begin{center}
\begin{tikzpicture}[every node/.style={inner sep=0pt, fill=white, font=\small}]
\node(A) {%
\begin{tabular}{@{}c|c|c|c|c|c|}
\multicolumn{1}{c}{ } & \multicolumn{1}{c}{ 0 } & \multicolumn{1}{c}{1} &
\multicolumn{1}{c}{ .. } & \multicolumn{1}{c}{ \textit{m-1} } & \multicolumn{1}{c}{ \textit{ m } } \\
\cline{2-6}
0 & & & \multicolumn{1}{c|}{ .. } & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
1 & & & \multicolumn{1}{c|}{ .. } & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{ .. } & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{ .. } & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
\textit{n-1} & & & \multicolumn{1}{c|}{ .. } & \multicolumn{1}{c|}{ } & \\
\cline{2-6}
\textit{n} & & & \multicolumn{1}{c|}{ .. } & \multicolumn{1}{c|}{} & \\
\cline{2-6}
\end{tabular}%
};
\node[right=3em] at (A.east) (B) {%
\begin{tabular}{@{}c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{1} &
\multicolumn{1}{c}{..} & \multicolumn{1}{c}{ \textit{m-1} } & \multicolumn{1}{c}{ \textit{ m } } \\
\cline{2-6}
0 & & \cellcolor{gray!75} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \cellcolor{gray!10} \\
\cline{2-6}
1 & \cellcolor{gray!40} & \cellcolor{gray!50} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \\
\cline{2-6}
. & & & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \cellcolor{gray!75} \\
\cline{2-6}
. & \cellcolor{gray!25} & \cellcolor{gray!50} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{ } & \cellcolor{gray!50} \\
\cline{2-6}
\textit{n-1} & \cellcolor{gray!25} & \cellcolor{gray!25} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{} & \cellcolor{gray!25} \\
\cline{2-6}
\textit{n} & & \cellcolor{gray!25} & \multicolumn{1}{c|}{..} & \multicolumn{1}{c|}{..} & \\
\cline{2-6}
\end{tabular}%
};
\node[right=3em] at (B.east) (C) {%
\begin{tabular}{@{}c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{ \textit{ m } } &
\multicolumn{1}{c}{0} & \multicolumn{1}{c}{..} & \multicolumn{1}{c}{ \textit{ m-1 } } \\
\cline{2-6}
& \cellcolor{gray!100} & \cellcolor{gray!75} & \multicolumn{1}{c|}{ \cellcolor{gray!50} } & \multicolumn{1}{c|}{ \cellcolor{gray!25} } & \cellcolor{gray!10} \\
\cline{2-6}
\end{tabular}%
};
\draw[->,thick] (A.east) ++(2pt,0pt) -- (B.west);
\draw[->,thick] (B.east) ++(2pt,0pt) -- (C.west);
\end{tikzpicture}
\end{center}
\end{document}