答案1
€编辑:全新的。
我选择了某种随机坐标,它们也可以是 foreach 循环中的明确坐标。
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{plotmarks}
\begin{document}
\begin{tikzpicture}[font=\sffamily,
mymark/.style={mark=square*, mark options={draw=red, fill=red!66!black, mark size=5pt}}
]
\def\List{1/Donald Duck/{2,3,4},
2/Bart Simpson/{2,3,4,5},
3/He-Man/{12,3,14},
4/Liam/{2,3,5,7,8,9,10,12,17},
5/Emma/{2,6,4},
6/Noah/{2,3,7,17},
7/Olivia/{2,3,8,1},
8/William/{2,9,10},
9/Ava/{2,3,11},
10/James/{12,3,4},
11/Isabella/{2,13,11},
12/Oliver/{2,3,5},
13/Sophia/{2,3,7},
14/Benjamin/{2,13,19},
15/Charlotte/{2,3,5},
16/Elijah/{2,3,16,17,1,2,5},
17/Mia/{2,3,17},
18/Lucas/{2,3,11},
19/Amelia/{12,13,12,17}}
\foreach \No/\Name/\Connection in \List{%%
\pgfmathsetmacro\x{\No+random(0,800)/100}
\pgfmathsetmacro\y{-1.5*mod(\No,7)}
\coordinate[] (N-\No) at (\x,\y);
\path[] plot[mymark] coordinates {(N-\No)} node[below=5pt]{\Name};
}%%
\begin{scope}[on background layer]
\foreach \No/\Name/\Connection in \List{%%
\foreach \End in \Connection \draw[red] (N-\No) -- (N-\End);
}%%
\end{scope}
\end{tikzpicture}
\end{document}