![如何在 tikz 中绘制连接的文本节点图?](https://linux22.com/image/381997/%E5%A6%82%E4%BD%95%E5%9C%A8%20tikz%20%E4%B8%AD%E7%BB%98%E5%88%B6%E8%BF%9E%E6%8E%A5%E7%9A%84%E6%96%87%E6%9C%AC%E8%8A%82%E7%82%B9%E5%9B%BE%EF%BC%9F.png)
我对 tikz 包非常陌生。有人能帮我在 tikz 包中写图表吗?
\begin{figure*}
\centering
\resizebox{\textwidth}{!}{
\begin{tikzpicture}[
textnode/.style={
draw,
rectangle split,
rectangle split horizontal,
rectangle split parts=2,
}
]
\path (-11, 0) node (a) {\includegraphics[width=2cm,height=2cm,keepaspectratio]{puppy}}
(-8.5, 0) node (b) {\includegraphics[width=2cm,height=2cm,keepaspectratio]{puppy}}
(-5.5,1) node[textnode] () {A \nodepart{two} B}
(-5.5,0) node[textnode] (c) {A \nodepart{two} B}
(-5.5,-1) node[textnode] () {A \nodepart{two} B}
(-3,0) node[textnode] (d) {A \nodepart{two} B}
(-1.5,1) node[textnode] () {A \nodepart{two} B}
(-1.5,0) node[textnode] (e) {A \nodepart{two} B}
(-1.5,-1) node[textnode] () {A \nodepart{two} B};
\draw[-stealth,shorten >=1pt,line width=0.5mm] (a) -- (b);
\draw[-stealth,shorten >=1pt,line width=0.5mm] (b) -- (c);
\draw[-stealth,shorten >=1pt,line width=0.5mm] (c) -- (d);
\draw[-stealth,shorten >=1pt,line width=0.5mm] (d) -- (e);
\end{tikzpicture}
}
\end{figure*}
答案1
使用矩阵(节点矩阵)和定位 tikz 库的选项。
结果:
梅威瑟:
\documentclass[tikz,border=14pt]{standalone}
\usepackage{tikz}
\usepackage{duckuments}
\usetikzlibrary{matrix,arrows.meta, positioning,fit,shapes}
\begin{document}
\begin{tikzpicture}[
%Environment config
>={Stealth[inset=0pt,length=6pt]},
font=\sffamily,
blue, % It draws all blue
thick,
%Environment Styles
MyMatrix/.style={
matrix of nodes,
line width=0.75pt,
column sep=-0.5pt,
row sep=-0.5pt,
text height=9pt,
text width =12pt,
text depth =3pt,
align=center,
nodes={draw},
nodes in empty cells
}
]
% Start Drawing the thing
\node(Img-1) at (0,0){
\includegraphics[
width=2cm,
height=2cm,
keepaspectratio
]{example-image-a}
};
\node[right=0.5 of Img-1](Img-2){
\includegraphics[
width=2cm,
height=2cm,
keepaspectratio
]{example-image-b}
};
\matrix[
MyMatrix,
right=0.5 of Img-2,
column 1/.style={nodes={draw=none}},
row 1/.style={nodes={draw=none}},
row 5/.style={nodes={draw=none}}
](M1){%Matrix contents
& A&B&C\\
1 & & & \\
2 & & & \\
3 & & & \\
\vdots&&\vdots&\\
N & & & \\
};
\matrix[
MyMatrix,
right=1cm of M1,
](M2){%Matrix contents
A&B\\
};
\matrix[
MyMatrix,
right=0.5 of M2,
column 1/.style={nodes={draw=none}},
row 1/.style={nodes={draw=none}},
row 5/.style={nodes={draw=none}}
](M3){%Matrix contents
& A\\
1 & \\
2 & \\
3 & \\
\vdots &\vdots\\
N & \\
};
%Draw details:
\draw[->] (Img-1)--(Img-2);
\draw[->] (Img-2)--(M1);
\draw[->] (M1)--(M2);
\draw[->] (M2)--(M3);
\end{tikzpicture}
\end{document}