我不明白为什么我的代码不能编译成所附的图像,不确定我是否遗漏了 Tikz 工作原理中的某些内容或者存在其他问题:
代码
\begin{tikzpicture}
\node[shape=circle,draw=black] (1) {$1$};
\node[shape=circle,draw=black] (2) [right of=1] {$2$};
\node[shape=circle,draw=black] (3) [below of=1] {$3$};
\node[shape=circle,draw=black] (4) [right of=3] {$4$};
\path[]
(4) edge [loop below] node (4)
(1) [-] edge node[right] (2)
(1) [-] edge node[below] (3)
(2) [-] edge node[above] (3);
\end{tikzpicture}
它应该是什么样子
它看起来像什么
答案1
路径中存在不必要的节点。(celi 解决了他们的答案通过添加{}
,这可以使代码编译但添加似乎未被使用的节点。)
\documentclass[border=3.14mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node[shape=circle,draw=black] (1) {$1$};
\node[shape=circle,draw=black] (2) [right of=1] {$2$};
\node[shape=circle,draw=black] (3) [below of=1] {$3$};
\node[shape=circle,draw=black] (4) [right of=3] {$4$};
\path[]
(4) edge [loop below] (4)
(1) [-] edge (2)
(1) [-] edge (3)
(2) [-] edge (3);
\end{tikzpicture}
\end{document}
答案2
这对我有用:
\begin{tikzpicture}
\node[shape=circle,draw=black] (1) {$1$};
\node[shape=circle,draw=black] (2) [right of=1] {$2$};
\node[shape=circle,draw=black] (3) [below of=1] {$3$};
\node[shape=circle,draw=black] (4) [right of=3] {$4$};
\path (1) edge [] node [left] {} (2)
(1) edge [] node [below] {} (3)
(2) edge [] node [above] {} (3)
(4) edge [loop above] node[] {} (4);
\end{tikzpicture}