4

I have drawn an ellipse:

\node (elli) [ellipse, minimum height=3cm,minimum width=2cm, draw] {};

I would like to write some elements in it as the figure below shows. The position of the elements do not need to be precise, but I want them to be inside the ellipse.

Does anyone know how to do it?

enter image description here

2

You can use the fit library to fit an ellipse node around some other nodes. The syntax is fit={(<node1>) (<node2>) ...}. To randomly place some nodes, you can use xshift=rnd*<length> and yshift=rnd*<length>. The random numbers change every minute, so to keep your results reproducible, you should fix the random seed using pgfmathsetseed=<integer>:

\documentclass[a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{fit,shapes}

\begin{document}

\pgfmathsetseed{12}

\begin{tikzpicture}[
    random position/.style={
        xshift=rnd*0.5cm,
        yshift=rnd*2cm
    }
]
\node (a) [random position] {1};
\node (b) [random position] {5};
\node (c) [random position] {7};
\node (d) [random position] {11};
\node (e) [random position] {$\cdots$};
\node [draw,ellipse,fit={(a) (b) (c) (d) (e)}] {};
\end{tikzpicture}


\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.