Cloud Shape in TikZ

  • This tutorial is about TikZ shapes, or more precisely TikZ node shapes. In this post, we will learn how to draw a TikZ cloud shapechange its sizeits anglesits color and access to all its anchors. Unlike the circle shape, this one requires loading shapes.symbols TikZ library.

Cloud shape in TikZ

Cloud shape is a part of the shapes.symbols TikZ library, so to work with this shape, we need to declare the library. The following line code draws a cloud shape by providing cloud key to the node command. The node is named (c) and drawn at the point with coordinates (0,0): 

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud, draw] (c) at (0,0) {};

\end{tikzpicture}

\end{document}

It should be noted that the cloud node will be drawn only if we provide draw option to the node command.

Add text to the cloud node

The previous code creates a cloud node with empty content. Text can be added inside the cloud node by putting it between the curly braces {} as follows.

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud, draw] (c) at (0,0) {Cloud};

\end{tikzpicture}

\end{document}

To fit the text inside the shape, this line of code yields to a cloud with a size depends on its content.

Cloud shape in TikZ

Change text color of the cloud node

In the previous section, we have added content to the cloud node and now we would like to change the text color. This can be achieved by providing the option text = <color> to the \node command:

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud, draw,text=cyan] (c) at (0,0) {Cloud};

\end{tikzpicture}

\end{document}
Change Text color node shape tikz

Add filling color to a node

The cloud node can be filled with any color using the option fill = <color>. Here is an illustrative example of a light gray filling with our cyan text:

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud, draw,text=cyan,fill = gray!10] (c) at (0,0) {Cloud};

\end{tikzpicture}

\end{document}
Change fill color node shape tikz

Change the border line color of a node

The cloud border color can be modified (default is black) by providing the color name to the draw option draw = <color>. Here is an example of a cloud filled with light gray, has cyan text and blue borders:

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud, draw =blue,text=cyan,fill = gray!10] (c) at (0,0) {Cloud};

\end{tikzpicture}

\end{document}
Change border color node shape tikz

Change the size of a cloud node

We mentioned above that the size of a cloud depends on its content. This is always true and we can set only the minimum size of a cloud. We can arrange a minimum size for its width with minimum width option, and similarly, we can set its height by using minimum height option. Below, we set the minimum width value to 3 cm and the minimum height value to 2 cm.

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud,
	draw =blue,
	text=cyan,
	fill = gray!10,
	minimum width = 3cm,
	minimum height = 2cm] (c) at (0,0) {Cloud};

\end{tikzpicture}

\end{document}
Change node size cloud shape tikz
  • If we need both the width and the length sizes to be the same, we can use minimum size option.

We can also change the width/height ratio of the cloud, using the aspect option. By default, the option is set to 1. To have a longer, slimmer cloud, we can set it to a parameter smaller than 1. Following line of code sets the aspect to 0.7.

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud,
	draw =blue,
	text=cyan,
	fill = gray!10,
	aspect=0.7] (c) at (0,0) {Cloud};

\end{tikzpicture}

\end{document}
Change aspect ratio of a node shape tikz

In a similar way, we can have wider clouds by setting their aspect option to a parameter larger than 1. Change aspect value to 1.5 in the above code and compile it!

Modify the cloud puffs

A cloud node shape consists of little arcs called puffs. By default, a cloud has 10 puffs. We can change this setting using cloud puffs option. Here is an example of a cloud with 16 puffs.

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud,
	draw =blue,
	text=cyan,
	fill = gray!10,
	aspect=1.5,
	cloud puffs = 16] (c) at (0,0) {Cloud};

\end{tikzpicture}

\end{document}
Cloud puffs number in TikZ

We can also change the length of these arcs. They are 135 degrees by default, but we can change this using cloud puff arc option. Below, we set the arc length of each cloud puff to 90 degrees.

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.symbols}

\begin{document}

\begin{tikzpicture}

\node[cloud,
	draw =blue,
	text=cyan,
	fill = gray!10,
	aspect=1.5,
	cloud puffs = 16,
	cloud puff arc = 90] (c) at (0,0) {Cloud};

\end{tikzpicture}

\end{document}
Cloud puffs arc in TikZ

Anchors of a cloud node

The advantage of using a node cloud is that it defines a set of anchors that we can use to get coordinates of the node borders or to position nodes with accuracy with respect to given coordinates. By default, node center is positioned at the provided coordinates ((0,0) for the previous examples)).

Cloud node anchors in TikZ
Cloud node anchors angles in TikZ
  • (c.south) represents the coordinates of the point located at the south of the cloud node where c is the node name. We can also use angles where (c.180) is the coordinates of the point located at the west of the cloud node.
  • For the cloud node shape, we can also use the tip points of puffs as anchors. The first puff is the one located at the north, and the rest of them goes counterclockwise. We can use them by calling them as puff 1, puff 2, etc.

Adding anchor = east will place the node point (c.east) at the provided coordinate (0,0). Check this post: how to annotate an image in LaTeX (Positioning Nodes using Anchors section).

Outer separation

The above anchors can be moved outside the node border by adding outer sep = <value> to the node command. Here is an example of anchors moved outside the node border with 10pt.

outer sep cloud shape TikZ
  • We reached the end of this post, If you have any questions or suggestionsleave me a comment or reach me via email at admin@latexdraw.com, I will be happy to hear from you!