我有这个代码
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=3cm,
thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (1) {a};
\node[main node] (2) [right of=1] {b};
\node[main node] (3) [right of=2] {c};
\node[main node] (4) [right of=3] {d};
\path[every node/.style={font=\sffamily\small}]
(1) edge node [right] {} (2)
(2) edge node [right] {} (3)
(3) edge node [right] {} (4)
(4) edge node [left] {} (1);
\end{tikzpicture}
\end{document}
生成以下图表:
我的目标是制作如下图表:
请原谅我画得不好。我尝试了和 的各种组合(4) edge node [bend left] {} (1);
,但(4) edge node [loop left] {} (1);
都无济于事。
答案1
只是为了展示另一种方法,这个用例正是键bend left
和bend right
被创建的用途:
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=3cm,
thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (1) {a};
\node[main node] (2) [right of=1] {b};
\node[main node] (3) [right of=2] {c};
\node[main node] (4) [right of=3] {d};
\path[every node/.style={font=\sffamily\small}]
(1) edge node [right] {} (2)
(2) edge node [right] {} (3)
(3) edge node [right] {} (4)
(4) edge[bend right] node [left] {} (1);
\end{tikzpicture}
\end{document}
这些键还接受一个可选<angle>
值,以便同时对称地设置in
和out
键,因此编写
(4) edge[bend right=90] node [left] {} (1);
将导致
如果需要对in
和密钥进行不对称设置,out
cfr 的解决方案是正确的做法。
答案2
一种方法是使用\draw
并指定入射角和出射角。只需指定节点名称即可构建相对于节点中心的路径(尽管不会从那里绘制)。您还可以指定节点锚点。例如,红线连接(4.north)
到(1.north)
。
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=3cm,
thick,main node/.style={circle,draw,font=\sffamily\Large\bfseries}]
\node[main node] (1) {a};
\node[main node] (2) [right of=1] {b};
\node[main node] (3) [right of=2] {c};
\node[main node] (4) [right of=3] {d};
\draw [->] (1) -- (2);
\draw [->] (2) -- (3);
\draw [->] (3) -- (4);
\draw [->] (4) to [out=150,in=30] (1);
\draw [->,red] (4.north) to [out=150,in=30] (1.north);
\end{tikzpicture}
\end{document}
答案3
如果这是问题的话,有几种绘制曲线的方法。以下是其中一种:
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
[
->,
>=stealth',
auto,node distance=3cm,
thick,
main node/.style={circle, draw, font=\sffamily\Large\bfseries}
]
\node[main node] (1) {a};
\node[main node] (2) [right of=1] {b};
\node[main node] (3) [right of=2] {c};
\node[main node] (4) [right of=3] {d};
\path[every node/.style={font=\sffamily\small}]
(1) edge node [right] {} (2)
(2) edge node [right] {} (3)
(3) edge node [right] {} (4);
\draw
(4) [out=150, in=20] to (1);
\end{tikzpicture}
\end{document}
以下是使其成为原始部分的方法\path
(edge
并稍微改变角度):
\path[every node/.style={font=\sffamily\small}]
(1) edge node [right] {} (2)
(2) edge node [right] {} (3)
(3) edge node [right] {} (4)
(4) edge [out=150, in=90] (1);