Draw an Ellipse in TikZ

  • In this tutorial, we will learn how to draw an ellipse, change its size and its color, add text content and access to its anchors. 

How to draw an ellipse in TikZ

Ellipse shape is a part of the shapes.geometric TikZ library, so to work with this shape, we need to declare the library. We need to add the following piece of code after the TikZ package declaration:

\usetikzlibrary{shapes.geometric}

An ellipse shape can be drawn by using the option ellipse to the \node command. Following line creates an ellipse node named (e) at coordinate (0,0).

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}
	\node[ellipse] (e) at (0,0) {};
\end{tikzpicture}

\end{document}

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

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}
	\node[ellipse,draw] (e) at (0,0) {};
\end{tikzpicture}

\end{document}
Ellipse shape TikZ

As you can see, the shape is a circle. The ellipse node acts as an ellipse when it is fitting to a text. Additionally, it can has different lengths for its width and height. We will go over these options in the next sections.

Add text to the ellipse node

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

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}
	\node[ellipse, draw] (e) at (0,0) {Ellipse};
\end{tikzpicture}

\end{document}

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

Ellipse shape in TikZ

Change text color of the ellipse node

In the previous section, we have added content to the ellipse 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.geometric}

\begin{document}

\begin{tikzpicture}
	\node[ellipse,
	draw,
	text = orange] (e) at (0,0) {Ellipse};
\end{tikzpicture}

\end{document}
Text color Ellipse shape in TikZ

Add filling color to a node

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

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}
	\node[ellipse,
	draw,
	text = orange,
	fill = cyan!20] (e) at (0,0) {Ellipse};
\end{tikzpicture}

\end{document}
Fill Ellipse shape in TikZ

Change the border line color of a node

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

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}
	\node[ellipse,
	draw = brown,
	text = orange,
	fill = cyan!20] (e) at (0,0) {Ellipse};
\end{tikzpicture}

\end{document}
change border color ellipse tikz

Change the size of an ellipse node

We mentioned above that the size of an ellipse depends on its content. This is always true and we can set only the minimum size of an ellipse. 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 2 cm and the minimum height value to 1.2 cm.

\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}
	\node[ellipse,
	draw = brown,
	text = orange,
	fill = cyan!20,
	minimum width = 2cm, 
	minimum height = 1.2cm] (e) at (0,0) {Ellipse};
\end{tikzpicture}

\end{document}
Ellipse size in TikZ
  • If we need both the width and the length sizes to be the same, we can use minimum size option. However using this option would give us a circle, so we can just use the circle command instead of an ellipse, check circle shape post!

Anchors of an ellipse node

The advantage of using a node ellipse 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).

Anchors of an ellipse shape tikz
Anchors angles of an ellipse shape tikz

(e.south) represents the coordinates of the point located at the south of the ellipse node where e is the node name. We can also use angles where (e.90) is the coordinates of the point located at the north of the ellipse node.

  • Adding anchor = east will place the node point (e.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 separation TikZ node shape
  • 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!