我有以下 TiKZ 图片:
\begin{tikzpicture}[scale=1,node distance=24]
\node (a) {(};
\node (b) [circle,right of=a] {(};
\node (c) [right of=b] {(};
\node (d) [right of=c] {A};
\node (e) [right of=d] { | };
\node (f) [right of=e] {B};
\node (g) [right of=f] {)};
\node (h) [right of=g] {*};
\node (i) [right of=h] {|};
\node (j) [right of=i] {C};
\node (k) [right of=j] {D};
\node (l) [right of=k] {*};
\node (m) [right of=l] {|};
\node (n) [right of=m] {E};
\node (o) [right of=n] {F};
\node (p) [right of=o] {G};
\node (q) [right of=p] {)};
\node (r) [right of=q] {*};
\node (s) [right of=r] {)};
\node (t) [right of=s] {*};
\path[->,draw=black!30!red] (a) edge node {} (b);
\path[->,draw=black!30!red] (b) edge node {} (c);
\path[->] (c) edge node {} (d);
\path[->,bend right] (c) edge node {} (f);
\path[->,draw=black!30!red] (d) edge node {} (e);
\path[->,draw=black!30!red,bend left] (e) edge node {} (g);
\path[->,draw=black!30!red] (f) edge node {} (g);
\path[->,draw=black!30!red] (g) edge node {} (h);
\path[->,draw=black!30!red,bend right] (h) edge node {} (c);
\path[->,draw=black!30!red,bend right] (c) edge node {} (h);
\path[->,draw=black!30!red] (h) edge node {} (i);
\end{tikzpicture}
这给了我这个输出,它接近我想要的,但我想把每个都圈出来\node
以便箭头更清晰。
将 each 更改\node
为\node[circle]
不起作用。我该怎么办?
答案1
简单的解决方案:用来draw
可视化圆圈。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\tikzstyle{mycirc}=[draw, circle, inner sep=2pt]
\begin{document}
\begin{tikzpicture}[scale=1,node distance=24]
\node (a) [mycirc,] {(};
\node (b) [mycirc,right of=a] {(};
\node (c) [mycirc,right of=b] {(};
\node (d) [mycirc,right of=c] {A};
\node (e) [mycirc,right of=d] { | };
\node (f) [mycirc,right of=e] {B};
\node (g) [mycirc,right of=f] {)};
\node (h) [mycirc,right of=g] {*};
\node (i) [mycirc,right of=h] {|};
\node (j) [mycirc,right of=i] {C};
\node (k) [mycirc,right of=j] {D};
\node (l) [mycirc,right of=k] {*};
\node (m) [mycirc,right of=l] {|};
\node (n) [mycirc,right of=m] {E};
\node (o) [mycirc,right of=n] {F};
\node (p) [mycirc,right of=o] {G};
\node (q) [mycirc,right of=p] {)};
\node (r) [mycirc,right of=q] {*};
\node (s) [mycirc,right of=r] {)};
\node (t) [mycirc,right of=s] {*};
\path[->,draw=black!30!red] (a) edge node {} (b);
\path[->,draw=black!30!red] (b) edge node {} (c);
\path[->] (c) edge node {} (d);
\path[->,bend right] (c) edge node {} (f);
\path[->,draw=black!30!red] (d) edge node {} (e);
\path[->,draw=black!30!red,bend left] (e) edge node {} (g);
\path[->,draw=black!30!red] (f) edge node {} (g);
\path[->,draw=black!30!red] (g) edge node {} (h);
\path[->,draw=black!30!red,bend right] (h) edge node {} (c);
\path[->,draw=black!30!red,bend right] (c) edge node {} (h);
\path[->,draw=black!30!red] (h) edge node {} (i);
\end{tikzpicture}
\end{document}
答案2
这个问题的答案已经在Excelsior 的答案。这只是说明您不必费力地手动添加所有节点,您可以使用链和一些将字符序列分解为节点的解析器。然后使用
\begin{scope}[start chain=going right,nodes={on chain,circle,draw}]
\tikzset{my parse={(((A|B)*|CD*|EFG)*)*}}
\end{scope}
如同
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,bending,chains}
\makeatletter
\tikzset{my parse/.code={\expandafter\mytikzcparse@i#1\pgfmath@token@stop}}
\def\mytikzcparse@i#1#2\pgfmath@token@stop{%
\node[alias=\@alph\tikzchaincount]{{$#1$}};%
\def\pgfutil@tmpa{#2}%
\unless\ifx\pgfutil@tmpa\empty
\expandafter\mytikzcparse@i#2\pgfmath@token@stop
\fi}
\makeatother
\begin{document}
\begin{tikzpicture}[>={Stealth[bend]}]
\begin{scope}[start chain=going right,nodes={on chain,circle,draw}]
\tikzset{my parse={(((A|B)*|CD*|EFG)*)*}}
\end{scope}
\path[->,draw=black!30!red] (a) to (b);
\path[->,draw=black!30!red] (b) to (c);
\path[->] (c) to (d);
\path[->,bend right] (c) to (f);
\path[->,draw=black!30!red] (d) to (e);
\path[->,draw=black!30!red,bend left] (e) to (g);
\path[->,draw=black!30!red] (f) to (g);
\path[->,draw=black!30!red] (g) to (h);
\path[->,draw=black!30!red,bend right] (h) to (c);
\path[->,draw=black!30!red,bend right] (c) to (h);
\path[->,draw=black!30!red] (h) to (i);
\end{tikzpicture}
\end{document}