我的序言是这样的:
\usepackage{graphicx,tikz}
\usetikzlibrary{matrix,arrows,positioning}
\setcounter{MaxMatrixCols}{20}
目前我正在使用这个:
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,
thick,main node/.style={square,fill=blue!20,draw,font=\sffamily\Large\bfseries}]
\matrix (m) [matrix of math nodes,nodes={rectangle,draw}, row sep=0.5em,
minimum size=2em, column sep=0em, text height=1.5ex, text depth=0.25ex]
{ 80 & \cdots & 166 & \quad & 195 & \cdots & 230 \\ };
\path[->,font=\scriptsize]
(m-1-1) edge[bend right=80] node[auto] {} (m-1-5)
(m-1-1) edge[bend right=80] node[auto] {} (m-1-6)
(m-1-2) edge[bend right=80] node[auto] {} (m-1-5)
(m-1-2) edge[bend right=80] node[auto] {} (m-1-7)
(m-1-3) edge[bend right=80] node[auto] {} (m-1-7)
(m-1-3) edge[bend right=80] node[auto] {} (m-1-5);
\node[fill=white,minimum size=2.1em] at (-0.025,0) {};
\path[->,font=\scriptsize]
(m-1-5) edge[bend right=80] node[auto] {} (m-1-3)
(m-1-5) edge[bend right=80] node[auto] {} (m-1-2)
(m-1-6) edge[bend right=80] node[auto] {} (m-1-1)
(m-1-6) edge[bend right=80] node[auto] {} (m-1-2)
(m-1-7) edge[bend right=80] node[auto] {} (m-1-3)
(m-1-7) edge[bend right=80] node[auto] {} (m-1-2);
\end{tikzpicture}
创造:
首先,这非常繁琐,我想知道是否有更好的方法在 TeX 中创建这样的图像。特别是,在矩形中创建间隙需要我通过猜测坐标将白色方形节点放在空节点上方。我觉得一定有更好的方法。此外,我该如何让其中一个节点填充为黄色?我能想到的唯一方法是用黄色方形节点覆盖该节点,然后再次猜测坐标的位置,直到看起来正确为止。请告诉我有更好的方法来做到这一点。
谢谢。
答案1
这是一种不用的方法\usetikzlibrary{matrix,arrows,positioning}
:
\documentclass[tikz, border=2]{standalone}
\begin{document}
\begin{tikzpicture}[->,>=stealth,shorten >=1pt,every node/.style={thick,rectangle,draw,minimum width=1cm,minimum height=1cm}]
\foreach [count=\i] \content/\fill in {80/yellow, \dots/none, 166/blue}
\node[fill=\fill] at (\i,0) (\i) {\content};
\foreach [count=\i from 5] \content/\fill in {195/none, \dots/red, 230/green}
\node[fill=\fill] at (\i,0) (\i) {\content};
\foreach \first/\second in {1/5,1/6,2/5,2/7,3/7,3/5,5/3,5/2,6/1,6/2,7/3,7/2}
\draw[->,thick] (\first) edge[bend right=80] (\second);
\end{tikzpicture}
\end{document}