我有以下 tikz 代码:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\begin{document}
\begin{tikzpicture}
\draw (10,10) node(C)[ellipse,draw] {C};
\draw (8.5,8.5) node(N)[ellipse,draw] {N};
\draw (11.2,8.5) node(Y)[ellipse,draw] {Y};
\draw (7.5,7.2) node(W)[ellipse,draw] {W};
\draw (9.3,7.2) node(K)[ellipse,draw] {K};
\draw [->] (C) -- (N) {N};
\draw [->] (C) -- (Y) {cc};
\draw [->] (N) -- (W) {dd};
\draw [->] (N) -- (K) {ee};
\end{tikzpicture}
\end{document}
它有几个问题。
1) 由于底部绘图命令,代码无法编译,我试图做的是在每个箭头旁边绘制一个标签。如果我删除所有 -> 命令的标签(例如 {cc} 或 {dd} 等),它会起作用,但它不会在边缘旁边显示标签。
- 我想要为 C 节点(标记为“T”)添加一个标记为“自循环”的标签,但是当我从一个节点到同一个节点绘制 -> 时,它不会绘制自循环。
答案1
像这样吗?
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[->]
\node[ellipse,draw] (C) at (10,10) {C};
\node[ellipse,draw] (N) at (8.5,8.5) {N};
\node[ellipse,draw] (Y) at (11.2,8.5) {Y};
\node[ellipse,draw] (W) at (7.5,7.2) {W};
\node[ellipse,draw] (K) at (9.3,7.2) {K};
\path (C) edge node[above] {C} (N);
\path (C) edge node[above,right] {cc} (Y);
\path (N) edge node[above,left] {dd} (W);
\path (N) edge node[above, right] {ee} (K);
\path (C) edge [loop above] node {T} (C);
\end{tikzpicture}
\end{document}