我使用 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}
請注意,中心底部節點和節點之間有一些空白z。另外,頂部節點和節點之間有空格y。
即使“振幅”設置為 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}