如何将矩形的左线和右线改为“之字形”?
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[decoration={zigzag,segment length=0.4em, amplitude=.3mm}]
\draw[] (0,3) edge[decorate] (0,0) --+ (0.5,0) edge[decorate, red] (0.5,0) edge[-]+ (0,0);
\draw[xshift=2cm] (0,0) rectangle (0.5,3);
\end{tikzpicture}
\end{document}
答案1
具有两个节点和不太明确的协调:
\documentclass[margin=5pt]{standalone}% if you load tikz afterward, no need to put it as documentclass option
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, positioning}
\tikzset{mynode/.style={inner sep=0pt, minimum width=.5cm, minimum height=3cm}}
\begin{document}
\begin{tikzpicture}[decoration={zigzag,segment length=0.4em, amplitude=.3mm}]
\node[mynode] (A) {};
\draw (A.north west) -- (A.north east) edge[decorate] (A.south east) (A.south east) -- (A.south west) edge[decorate] (A.north west);
\node[mynode, right=1.5cm of A, draw] {};
\end{tikzpicture}
\end{document}
正如 Ross 所建议的,line cap=round
选择\draw
:
\draw[line cap=round] (A.north west) -- (A.north east) edge[decorate] (A.south east) (A.south east) -- (A.south west) edge[decorate] (A.north west);
连接更好:
另一位专家告诉我,可以不用edge
s 来装饰部分路径:
\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, positioning}
\tikzset{mynode/.style={inner sep=0pt, minimum width=.5cm, minimum height=3cm}}
\begin{document}
\begin{tikzpicture}[decoration={zigzag,segment length=0.4em, amplitude=.3mm}]
\node[mynode] (A) {};
\draw[line cap=round] (A.north west) -- (A.north east) decorate{-- (A.south east)} -- (A.south west) decorate{-- cycle};
\node[mynode, right=1.5cm of A, draw] {};
\end{tikzpicture}
\end{document}
答案2
尝试重复一些坐标:
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[decoration={zigzag,segment length=0.4em, amplitude=.3mm}]
\draw[] (0,0) edge [decorate] (0,3) (0,3) -- (0.5,3) (0.5,3) edge [decorate] (0.5,0) (0.5,0) -- (0,0);
\draw[xshift=2cm] (0,0) rectangle (0.5,3);
\end{tikzpicture}
\end{document}