\begin{table}[!htb]
\begin{minipage}{.5\linewidth}
\caption{}
\centering
\begin{tabular}{|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}
\hline
D & 1 & 0 & 1 & D & 1 & 1 \\
\hline
\end{tabular}\vspace{0.8 cm}
\begin{tabular}{|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}
\hline
D & 1 & 0 & 1 & D & 1 & 1 \\
\hline
\end{tabular}
\end{minipage}\vspace{-1.5cm}
$\Rightarrow$
\begin{minipage}{.5\linewidth}
\centering
\caption{}
\begin{tabular}{|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}
\hline
D & 1 & 0 & 1 & D & 1 & 1 \\
\hline
\end{tabular}\vspace{0.8 cm}
\begin{tabular}{|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}
\hline
D & 1 & 0 & 1 & D & 1 & 1 \\
\hline
\end{tabular}
\end{minipage}
\end{table}
答案1
您可以在 tikzpicture 环境和 tikz 节点的帮助下绘制箭头。
这是代码..
\documentclass[margin=1in]{standalone}
\usepackage{tikz}
\usetikzlibrary[arrows, decorations.pathmorphing, backgrounds, positioning, fit, petri, calc]
\usetikzlibrary{shapes.arrows}
\begin{document}
\begin{tikzpicture}[node distance=0pt,
bluebox/.style={draw, fill=cyan!50, text width=0.5cm, inner sep=0.1cm, align=center},
box/.style={draw, text width=0.5cm, inner sep=0.1cm, align=center}]
\begin{scope}
\node[bluebox] (b7) {0};
\node[bluebox] (b6) [right=of b7] {1};
\node[bluebox] (b5) [right=of b6] {0};
\node[bluebox] (b4) [right=of b5] {1};
\node[bluebox] (b3) [right=of b4] {0};
\node[bluebox] (b2) [right=of b3] {1};
\node[bluebox] (b1) [right=of b2] {1};
\node[box, yshift=-1.25cm] (a7) {1};
\node[box] (a6) [right=of a7] {1};
\node[box] (a5) [right=of a6] {1};
\node[box] (a4) [right=of a5] {0};
\node[box] (a3) [right=of a4] {0};
\node[box] (a2) [right=of a3] {1};
\node[box] (a1) [right=of a2] {0};
\draw[->, very thick] ($(a6.south east) + (0,-0.25cm)$) node[yshift=2.5cm] {crossover point} node[yshift=-0.15cm] {Parent chromosomes} -- ($(b6.north east) + (0,0.25cm)$);
\end{scope}
\node[draw, single arrow,
minimum height=30mm, minimum width=20mm,
single arrow head extend=2mm,
anchor=west, rounded corners=2pt, right of=b1, xshift=2.25cm, yshift=-0.75cm] (arrow) {};
\node [above=of arrow, yshift=1.5cm]{One Point Crossover};
\begin{scope}[xshift=9cm]
\node[bluebox] (b7) {0};
\node[bluebox] (b6) [right=of b7] {1};
\node[box] (b5) [right=of b6] {1};
\node[box] (b4) [right=of b5] {0};
\node[box] (b3) [right=of b4] {0};
\node[box] (b2) [right=of b3] {1};
\node[box] (b1) [right=of b2] {0};
\node[box, yshift=-1.25cm] (a7) {1};
\node[box] (a6) [right=of a7] {1};
\node[bluebox] (a5) [right=of a6] {0};
\node[bluebox] (a4) [right=of a5] {1};
\node[bluebox] (a3) [right=of a4] {0};
\node[bluebox] (a2) [right=of a3] {1};
\node[bluebox] (a1) [right=of a2] {1};
\node [below of=a4, yshift=-0.75cm] {Offspring chromosomes};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
解决方案pstricks
:我插入了 2 个\rnode
,然后用节点连接将它们连接起来。对于 bigarrow,我加载pst-arrow
并用于\psBigArrow
连接一个空节点 ( \pnode
),该节点放置在第一个 minipage 的末尾,另一个放置在第二个 minipage 的开头。
\documentclass[11pt]{article}
\usepackage{geometry}
\usepackage{array, caption}
\usepackage[table, svgnames]{xcolor}
\usepackage{pst-node, pst-arrow}
\colorlet{mygrey}{Gainsboro!50!Lavender}
\begin{document}
\begin{table}[!htb]
\sffamily\setlength{\extrarowheight}{2pt}
\begin{minipage}{.35\linewidth}
\centering
\begin{tabular}{|*{7}{wc{0.3cm}|}}
\multicolumn{7}{l}{\hskip 1.5em\rnode[bl]{C}{Crossover point}} \\[1.5ex]
\hline
\rowcolor{mygrey} D & 1 & 0 & 1 & D & 1 & 1 \\
\hline
\noalign{\vspace{0.4cm}}
\hline
D & 1 & 0 & 1 & D & 1 & 1 \\
\hline
\noalign{\vskip 1.5ex}
\multicolumn{7}{l}{\hskip1.5em\rnode[tl]{P}{Parent chromosomes}}
\end{tabular}
\end{minipage}%
\pnode[0.5em,1.2ex]{A} \hspace{2.2cm}\pnode[-0.5em,1.2ex]{W}
\begin{minipage}{.35\linewidth}
\centering
\begin{tabular}{|*{7}{p{0.3cm}|}}
\multicolumn{5}{c}{} \\[1.5ex]
\hline
\cellcolor{mygrey}D & \cellcolor{mygrey}1 & 0 & 1 & D & 1 & 1 \\
\hline
\noalign{\vspace{0.4cm}}
\hline
\rowcolor{mygrey}\cellcolor{white} D &\cellcolor{white} 1 & 0 & 1 & D & 1 & 1 \\
\hline\noalign{\vskip 1.5ex}
\multicolumn{7}{c}{\hskip1.5em\rnode{O}{offspring chromosomes}}
\end{tabular}
\end{minipage}
\ncline[arrows=->, arrowinset=0.12, nodesep=2pt, offset =-22pt]{P}{C}
\psBigArrow[doublesep=3mm](A)(W)
\end{table}
\end{document}
答案3
TikZ 的另一个解决方案:
- 画在循环中
- 使用的库
chains
- 盒子的条件着色
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
calc, chains,
fit,
positioning,
shapes.arrows}
\begin{document}
\begin{tikzpicture}[
node distance = 7mm and 0mm,
start chain = going right,
ARR/.style = {single arrow, single arrow head extend=2mm, draw,
minimum height=5.5em, minimum width=13mm},
box/.style = {draw, fill=#1, minimum width=1.6em, outer sep=0pt},
box/.default = cyan!50,
]
\foreach \i [count=\j] in {0,1, 0,1, 0,1, 1}
{
\node (n1\j) [box,on chain] {\i};
\ifnum\j<3
\node [box,right=17em of n1\j] {\i};
\else
\node [box=white,right=17em of n1\j] {\i};
\fi
}
\foreach \i [count=\j] in {1,1, 1,0, 0,1, 0}
{
\node (n2\j) [box=white, below=of n1\j] {\i};
\ifnum\j<3
\node [box=white,right=17em of n2\j] {\i};
\else
\node (n4\j) [box,right=17em of n2\j] {\i};
\fi
}
%
\draw[-Straight Barb, very thick] ([yshift=-3mm] n22.south east)
node (aux1) [align=center, below] {Parent\\ chromosomes} --
([yshift=+3mm] n12.north east)
node (aux2) [align=center, above] {crossover\\ point};
\node[align=center, below] at (aux1.north -| n44) {offsping\\ chromosomes};
%
\node [ARR,right=1em] at ($(n17.east)!0.5!(n27.east)$) {};
%
\node [draw, rounded corners, fit = (aux1) (aux2) (n47),
label={[anchor=north]north: One Point Crossover}] {};
\end{tikzpicture}
\end{document}
答案4
使用一些 TikZ 矩阵:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.arrows}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc}
\tikzset{
mymatr/.style={
matrix of nodes,
inner sep=0pt,
draw, very thick,
nodes={
draw, very thin,
minimum size=18pt,
}
},
descr/.style={
font=\bfseries,
inner xsep=0pt
}
}
\begin{document}
\begin{figure}\centering
\begin{tikzpicture}
\matrix[mymatr, nodes={fill=cyan!50}] (matrA) {0&1& 0&1& 0&1& 1\\};
\matrix[mymatr,below =.5cm of matrA] (matrB) {1&1& 1&0& 0&1& 0\\};
\matrix[mymatr,right =2.5cm of matrA] (matrC)
{|[fill=cyan!50]|0&|[fill=cyan!50]|1& 1&0& 0&1&0\\};
\matrix[mymatr,below =.5cm of matrC] (matrD)
{1&1&|[fill=cyan!50]| 0&|[fill=cyan!50]|1&
|[fill=cyan!50]|0&|[fill=cyan!50]|1&|[fill=cyan!50]| 1\\};
\coordinate (AB) at ($(matrA.south east)!.5!(matrB.north east)$);
\coordinate (CD) at ($(matrC.south west)!.5!(matrD.north west)$);
\coordinate (ABCD) at ($(AB)!.5!(CD)$);
\node[draw, single arrow, minimum height=2cm, minimum width=1.2cm,
single arrow head extend=3pt,
single arrow tip angle=100] (myar) at (ABCD) {};
\draw[-Triangle, very thick,
shorten >=-10pt,
shorten <=-10pt]
(matrB-1-2.south east) -- (matrA-1-2.north east);
\node[above=10pt, descr, anchor=south west] at (matrA-1-1.north east)
{Crossover point};
\node[below=10pt, descr, anchor=north west] at (matrB-1-1.south east)
{Parent chomosomes};
\node[below=10pt, descr, anchor=north west] (myd) at (matrD-1-1.south)
{offspring chomosomes};
\node[above=40pt of myar, descr] (title) {One point Crossover};
\node[draw, densely dotted, very thick, fit=(matrA)(title)(myd)(matrD),
rounded corners, inner sep=6pt]{};
\end{tikzpicture}
\caption{My figure caption.}
\end{figure}
\end{document}