I want to construct a rectangle with two sides having a slight curvature and the other two sides being zigzag lines. In the end, I want to fill it. While the construction of the path worked the way I expected, the filling did not. How can I tell TikZ to fill the area inside this rectangle?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, decorations}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[scale=2]
\coordinate (A) at (0,0);
\coordinate (B) at (8,0);
\coordinate (C) at (8,2);
\coordinate (D) at (0,2);
\begin{scope}[decoration=zigzag]
\def\mypath{ (A) to[out=10,in=170] (B)
decorate[decoration=zigzag] {(B)-- (C)} (C) to[out=170,in=10] (D)
decorate[decoration=zigzag]{(D)--(A)}
};
\draw [fill=red] \mypath;
\end{scope}
\end{tikzpicture}
\end{document}
Best Answer
You are breaking the path into pieces by repeating the coordinate names
(B)
and(D)
hence each piece is filled individually. Removing them inside the braces (and the extra(C)
) fixes the problem.