我正在使用 tikz 在节点之间绘制蛇形线圈边/路径,但某些边在其起始或终止节点之前/之后有空白。这是一个小例子:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary[positioning,decorations.pathmorphing]
\begin{document}
\begin{tikzpicture}
\tikzstyle{enclosed} = [draw, circle, inner sep=0pt, minimum size=.15cm, fill=black]
\tikzstyle{enclosedM} = [draw, circle, inner sep=0pt, minimum size=.15cm, fill=red]
\node[enclosed, label={left: $x$}] (x) at (0,2) {};
\node[enclosed, label={right: $y$}] (y) at (4,2) {};
\node[enclosed] (w) at (2,0) {};
\node[enclosed] (v) at (2,4) {};
\node[enclosedM, label={above: $z$}] (z) at (2,1) {};
\node[enclosedM, label={below: $t$}] (t) at (2,3) {};
\draw[decorate,decoration={snake,amplitude=.2mm}]
(x) -- (v)
(v) -- (y)
(x) -- (w)
(w) -- (y)
(x) -- (t)
(v) -- (t)
(y) -- (t)
(x) -- (z)
(w) -- (z)
(z) -- (y);
\end{tikzpicture}
\end{document}
请注意,中心底部节点和节点之间有一些空白是。此外,顶部节点和节点之间有空格是。
即使将“振幅”设置为 0mm,这种情况仍然会发生,我认为这相当于边缘根本没有装饰。使用各种组合设置“后长度”和“预长度”选项可以修复某些边缘,但随后会在其他之前没有问题的边缘上产生同样的问题。
如果我删除decorate, decorations={...}
并正常使用\draw
而不进行任何设置,它可以正常工作,但边缘不会起波纹。我怎样才能去除空白,使其表现为正常边缘但半起波纹?
答案1
你必须小心处理装饰。我不太清楚为什么会发生这种情况,但显然是因为你将多个段放入了一个\draw
命令中。
您应该\draw
为每个线段单独编写一个。或者,为了使其与原始版本相似,您可以使用以下代码:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\tikzset{
enclosed/.style={draw, circle, inner sep=0pt, minimum size=.15cm, fill=black},
enclosedM/.style={enclosed, fill=red}
}
\node[enclosed, label={left: $x$}] (x) at (0,2) {};
\node[enclosed, label={right: $y$}] (y) at (4,2) {};
\node[enclosed] (w) at (2,0) {};
\node[enclosed] (v) at (2,4) {};
\node[enclosedM, label={above: $z$}] (z) at (2,1) {};
\node[enclosedM, label={below: $t$}] (t) at (2,3) {};
\foreach\x in {
(x) -- (v),
(v) -- (y),
(x) -- (w),
(w) -- (y),
(x) -- (t),
(v) -- (t),
(y) -- (t),
(x) -- (z),
(w) -- (z),
(z) -- (y)
}
\draw[decorate,decoration={snake,amplitude=.2mm}] \x;
\end{tikzpicture}
\end{document}
答案2
两条评论(不是真正的答案):tikzstyle
已被弃用,如果你逐个绘制线条,则不会出现问题。 (我还没有检查问题是否是由于tikzstyle
。)更新:压缩了代码,非常感谢@Zarko 捕获方括号!
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\tikzset{Snake/.style={decorate,decoration={snake,amplitude=.2mm}},
enclosed/.style={draw, circle, inner sep=0pt, minimum size=.15cm,
fill=black},
enclosedM/.style={draw, circle, inner sep=0pt, minimum size=.15cm,
fill=red}}
\node[enclosed, label={left:$x$}] (x) at (0,2) {};
\node[enclosed, label={right:$y$}] (y) at (4,2) {};
\node[enclosed] (w) at (2,0) {};
\node[enclosed] (v) at (2,4) {};
\node[enclosedM, label={above:$z$}] (z) at (2,1) {};
\node[enclosedM, label={below:$t$}] (t) at (2,3) {};
\foreach \X in {x,y,v} \draw[Snake] (t) -- (\X);
\foreach \X in {x,y,w} \draw[Snake] (z) -- (\X);
\foreach \X in {x,y}{\foreach \V in {v,w} \draw[Snake] (\V) -- (\X);}
\end{tikzpicture}
\end{document}