# TikZ shapes: Circle

• This tutorial is one of post series about predefined TikZ shapes, or more precisely TikZ node shapes. In this post, we will learn how to create a TikZ circle node shape, change its size, its color and access to all its anchors.

## Node shape circle in TikZ

A circle node shape can be created by providing the option circle to the \node command. The following line code creates a circle node named (c) at the point with coordinates (0,0):

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

Compiling this line of code displays nothing. The circle node will be drawn only if we provide draw option to the node command as follows:

\node[circle,draw] (c) at (0,0){};
• The circle node shape is always defined and no TikZ library is needed to be loaded

### Add text to the circle node

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

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

Compiling this line code yields to a circle with a size depends on its content:

### Change text color of a node

In the previous section, we have added content to the circle 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:

\node[circle,draw,text=orange] (c) at (0,0){Circle};

### Add filling color to a node

The circle node can be filled with any color using the option fill=<color>. Here is an illustrative example of light gray filling and text with white color:

\node[circle,draw,text=white,fill=lightgray] (c) at (0,0){Circle};

### Change the border line color of a node

The circle 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 circle filled with light gray and has white text and brown border:

\node[circle,
draw=brown,
text=white,
fill=lightgray] (c) at (0,0){Circle};

### Change the size of a circle node

We mentioned above that the size of circle depends on its content. This is always true and we can set only the minimum size of a circle using the option minimum size =<value>.

### Anchors of a circle node

The advantage of using a node circle is that it defines a set of anchors that we can use them to get coordinates of the node border 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).

(c.north) represents the coordinates of the point located at the north of the circle 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 circle node.

However, adding anchor=west will place the node point (c.west) 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.

## Tikzstyle Command

To avoid repeating options inside node commands, we can regroup them using \tikzstyle command and we set a name to this style. The tikzstyle commad is used as follows:

\tikzstyle{StyleName}=[options]

Check the example of Discrete event system to get an idea how to use it!

## TikZ Example 1 : Discrete event system

In the next code, we use node circle shapes to draw the discrete event system shown below. We create nodes at different positions: (0,0), (4,0) and (2,2.5). Each one has a minimum size equals to 1.25cm.

Each node is filled with OliveGreen color and has text written with white color (check the predefined color in LaTeX: dvipsnames).

\documentclass[border=0.2cm]{standalone}

% More defined colors
\usepackage[dvipsnames]{xcolor}

% Required package
\usepackage{tikz}

% Create style for node circles
\tikzstyle{state}=[
circle,
minimum size =1.25cm
draw=black,
thick,
fill=OliveGreen,
text=white
]

\begin{document}

\begin{tikzpicture}[-stealth,thick,text=OliveGreen]

% State q2
\node[state] (A) at (0,0){$q_2$};

% State q1
\node[state] (B) at (4,0){$q_1$};

% State q0
\node[state] (C) at (2,2.5){$q_0$};

% Transition q2 to q0
\draw (A) to[bend left] node[left]{$e_3$}(C) ;

% Transition q0 to q1
\draw (C) to[bend left] node[right]{$e_1$}(B);

% Transition q1 to q2
\draw (B) to[bend left]node[below]{$e_2$} (A);

% Initial state
\draw (2,4) -- node[left]{$e_0$}(C.north);

\end{tikzpicture}

\end{document}
• It should be noted that the xcolor pachage must be loaded before the TikZ package to avoid error messages.

## TikZ Example 2 : Control block diagram

• We've reached the end of this tutorialIf you have any questions or remarks, leave me a comment below or reach me via e-mail at admin@latexdraw.com, I will be happy to hear from you!

### 4 thoughts on “TikZ shapes: Circle”

1. In this diagram (below “Outer separation”) there is an anchor named c.text seemingly designating the left end of the node text baseline. The “text” anchor works with TikZ 3.1.8b but I’m failing to find it in the respective pgfmanual.pdf. How is this related to “base west” which I’m used to?

• Hi Moss,

The c.text is related to the left end of the text baseline.
c.base west is located at the border of the node containing the text. Please check page 786 of the PGF manual v3.1.8b for more details.

2. Where you give examples of adding a text to a node, there is a word ‘Circle’ missing in the code.

• Correct!
Many thanks Rafal, I’ve rectified it 🙂!