1

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??

2

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) : result

| improve this answer | |
  • Thank You very much! – Martund Jul 24 at 16:57
1

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.

screenshot

\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}
| improve this answer | |
  • Thank You very much! – Martund Jul 24 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.