
「完成」用於\draw
完成形狀的線條需要什麼?
\documentclass{letter}
\usepackage{tikz}
\begin{document}
\tikzset{every picture/.style=thick}
\begin{tikzpicture}[scale=0.2]
\draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- (11,-1);
\draw(12,8) arc (-90:180:1);
\draw(12,8) -- (12,9) -- (11,9);
\end{tikzpicture}
\end{document}
角落在某些角落呈鋸齒狀,或在其他角落「刺穿」形狀。
答案1
規則如下:
- 使用完整的單一路徑,或使用下面評論中您自己的話:「一口氣畫出來」。也就是說,不要使用多個
\draw
,\path
or so 指令。也要確保沒有間隙。 - 新增
-- cycle
以關閉閉合路徑。 - 可選:使用適當的線路連接。
應用於你的圖片,這會產生
\documentclass[tikz, border=3mm]{standalone}
\begin{document}
\tikzset{every picture/.style=thick}
\begin{tikzpicture}[scale=0.2]
\begin{scope}
\draw (12,4) -- (12,3) arc (-90:180:1) -- cycle;
\draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- cycle;
\end{scope}
\begin{scope}[xshift=3.5cm,line join=round]
\draw (12,4) -- (12,3) arc (-90:180:1) -- cycle;
\draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- cycle;
\end{scope}
\begin{scope}[xshift=7cm,line join=bevel]
\draw (12,4) -- (12,3) arc (-90:180:1) -- cycle;
\draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- cycle;
\end{scope}
\begin{scope}[xshift=10.5cm,miter limit=1]
\draw (12,4) -- (12,3) arc (-90:180:1) -- cycle;
\draw (11,-1) -- (13,-1) -- (13,1) -- (11,1) -- (13,0) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}
這調查了一些不同的線路連接選項,請參閱第 17 頁。 pgfmanual v3.1.4 的 172 了解更多。
當然,如果您將不同的路徑拼湊在一起以獲得良好的線連接,那麼您可能必須恢復某些線段的方向,或者至少有利於恢復某些線段的方向。例如,當將問題附錄的三個部分拼湊在一起時,我恢復了一個弧線以獲得
\documentclass[tikz, border=3mm]{standalone}
\begin{document}
\tikzset{every picture/.style=thick}
\begin{tikzpicture}[scale=0.25]
\draw (5,7) -- (7,5) -- (5,5) -- (7,7)
arc (90:180:1) arc (0:90:1) -- cycle;
\end{tikzpicture}
\end{document}
路徑可以縮短為
\draw (7,5) -- (5,5) -- (7,7) arc (90:180:1) arc (0:90:1) -- cycle;