# How to add finishing to a zig-zag line in tikzpicture

Consider the following MWE

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[thick] (3,-0.5)--(3,-0.8)--(0.2,-0.8)--(0.2,0.8)--(3,0.8)--(3,0.5);
\draw[thick,decoration={zigzag,segment length=2mm}] decorate{(3,-0.5)--(3,0.5)};
\end{tikzpicture}
\end{center}
\end{document}


This is the output shown by this code:

Note that the point where the zigzag and the straight lines combine doesn't have nice finishing, as shown in this figure.

How to achieve the correct finishing??

Splitting a \draw command into two is not a good idea. Try like this:

\begin{tikzpicture}
\draw[thick] (3,-0.8)--(0.2,-0.8)--(0.2,0.8)--(3,0.8)--(3,0.5) decorate [decoration={zigzag,segment length=2mm}] { -- (3,-0.5)} -- cycle;
\end{tikzpicture}


Result (zoomed in) :

• Thank You very much! – Martund Jul 24 at 16:57

Your figure is composed of two paths and is therefore not closed, which is why there is this discontinuity. The idea is to make a single closed path and using the options pre=lineto,pre length=5pt,post=lineto,post length=5pt just give the coordinates of the four vertices of the rectangle.

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}

\begin{tikzpicture}
\draw[thick](3,-0.8)--(0.2,-0.8)--(0.2,0.8)--(3,0.8)
decorate[decoration={zigzag,segment length=2mm,pre=lineto,pre length=5pt,post=lineto,post length=5pt}] {--cycle};
\end{tikzpicture}

\end{document}

• Thank You very much! – Martund Jul 24 at 16:58