# TikZ clip shapes using several (built in) shapes

I'm looking for a way to draw one image composed of a union of multiple cloud shapes. The following MWE:

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
\newcommand{\CloudDist}{1.8}

\tikzstyle {cloudkeys} = [cloud puffs=30, cloud puff arc=150, aspect=1.25, inner sep=0.7cm,]
\tikzstyle {mycloud}   = [draw, cloud, cloudkeys, fill=blue!25, nearly opaque]

\coordinate (cloud 0);
\coordinate [right=\CloudDist cm of cloud 0] (cloud 1);
\coordinate [right=\CloudDist cm of cloud 1] (cloud 2);

\foreach \x in {0,1,2} {
\node [mycloud] at (cloud \x) (local map cloud shape \x) {};
}
\end{tikzpicture}
\end{document}


produces this figure:

but the desired result is something like this one:

I found some answers that almost showed me how to do it.

• Answers in this question shows how to clip shapes with another (single) shape;
• Answers in two other questions (here and here) shows how to invert a clip selection using basic shapes or paths.

I think what want to do can be achieved with a mix of these answers, but I couldn't do it myself. I would appreciate if someone can show me how to draw this figure.

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – TeXnician Feb 24 '17 at 21:32

You can use clipping, but the other solution is simpler. Note that the nodes anchors do not form a rectangle.

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
\newcommand{\CloudDist}{1.8}

\tikzstyle {cloudkeys} = [cloud puffs=30, cloud puff arc=150, aspect=1.25, inner sep=0.7cm,]
\tikzstyle {mycloud}   = [draw, cloud, cloudkeys, fill=blue!25, nearly opaque]

\coordinate (cloud 0);
\coordinate [right=\CloudDist cm of cloud 0] (cloud 1);
\coordinate [right=\CloudDist cm of cloud 1] (cloud 2);

\path (cloud 0) -- (cloud 1) coordinate[midway] (cloud edge 1);
\path (cloud 1) -- (cloud 2) coordinate[midway] (cloud edge 2);

\begin{scope}
\node[cloud, cloudkeys,outer sep=2pt] (temp) at (cloud 0) {};% invisible, used for clip rectangle
\clip (temp.south -| temp.west) rectangle (temp.north -| cloud edge 1);
\node [mycloud] at (cloud 0) (local map cloud shape 0) {};
\end{scope}
\begin{scope}
\node[cloud, cloudkeys,outer sep=2pt] (temp) at (cloud 1) {};% invisible, used for clip rectangle
\clip (temp.south -| cloud edge 1) rectangle (temp.north -| cloud edge 2);
\node [mycloud] at (cloud 1) (local map cloud shape 1) {};
\end{scope}
\begin{scope}
\node[cloud, cloudkeys,outer sep=2pt] (temp) at (cloud 2) {};% invisible, used for clip rectangle
\clip (temp.south -| cloud edge 2) rectangle (temp.north -| temp.east);
\node [mycloud] at (cloud 2) (local map cloud shape 2) {};
\end{scope}

\end{tikzpicture}
\end{document}


• This is way more simpler than what I was trying to do. Thanks! – Ellon Paiva Feb 26 '17 at 9:17

No clipping is needed.

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
\newcommand{\CloudDist}{1.8}

\tikzstyle {cloudkeys} = [cloud puffs=30, cloud puff arc=150, aspect=1.25, inner sep=0.7cm,]
\tikzstyle {mycloud1}   = [draw, cloud, cloudkeys, fill=blue!25]
\tikzstyle {mycloud2}   = [      cloud, cloudkeys, fill=blue!25]

\coordinate (cloud 0);
\coordinate [right=\CloudDist cm of cloud 0] (cloud 1);
\coordinate [right=\CloudDist cm of cloud 1] (cloud 2);

\begin{scope}[transparency group,nearly opaque]
\foreach \x in {0,1,2} {
\node [mycloud1] at (cloud \x) (local map cloud shape \x) {};
}
\foreach \x in {0,1,2} {
\node [mycloud2] at (cloud \x) (local map cloud shape \x) {};
}
\end{scope}
\end{tikzpicture}
\end{document}


• Thanks! I really like your solution, but I have some problems using it in my document. In fact, my MWE is a simple version of a more complex picture. If I adapt the complex figure to use your solution, the cloud lines gets too thin, almost fading. The weird thing is that if I compile it as a standealone picture I get the desired result, but not when it is in the document. So for now I'm accepting the answer of @John Kormylo as the right answer, just because it worked in my document, although I find yours more elegant. – Ellon Paiva Feb 26 '17 at 9:46