How to get a ellipse shaped node in Tikz Network?

Actually, your shape is an ellipse. It just happens to be the same height and width, because those are the default settings. You can give extra TikZ options using the style option of \Vertex.

\documentclass{article}
\usepackage{tikz-network}
\begin{document}

\begin{tikzpicture}
    \Vertex[color=white, x=-1, y=1, label=A]{A}
    \Vertex[color=white, x=1, y=1, label=B, shape=rectangle]{B}
    \Vertex[color=white, x=0, y=0, label=2, shape=ellipse, style={minimum width=2cm}]{2}
    \Edge[lw=1, Direct](A)(2)
    \Edge[lw=1, Direct](B)(2)
\end{tikzpicture}

\end{document}

MWE output


Let me start by spelling out your and and Joule V's observation that the text will just overshoot if is longer than the package expects it to be.

\documentclass{article}
\usepackage{tikz-network}
\begin{document}

\begin{tikzpicture}
    \Vertex[color=white, x=-1, y=1, label=A]{A}
    \Vertex[color=white, x=1, y=1, label=B, shape=rectangle]{B}
    \Vertex[color=white, x=0, y=0, label=2222222, shape=ellipse]{2}
    \Edge[lw=1, Direct](A)(2)
    \Edge[lw=1, Direct](B)(2)
\end{tikzpicture}

\end{document}

enter image description here

Needless to say that this looks a bit suboptimal. The internal reason why that happens is that the text is not the node contents, as one may naively suspect/hope, but, as the label indicates, a label. This problem can be solved as follows:

\documentclass{article}
\usepackage{tikz-network}
\makeatletter
\tikzset{network x offset/.initial=1ex,network y offset/.initial=1ex,
adjust size/.style={minimum width=width("\vertex@Label")+2*\pgfkeysvalueof{/tikz/network x offset},
minimum height=height("\vertex@Label")+2*\pgfkeysvalueof{/tikz/network y offset}}}
\makeatother
\begin{document}

\begin{tikzpicture}
    \Vertex[color=white, x=-1, y=1, label=A]{A}
    \Vertex[color=white, x=1, y=1, label=B, shape=rectangle]{B}
    \tikzset{every label/.append style={}}
    \Vertex[color=white, x=0, y=0, label=2222222, shape=ellipse,
    style={adjust size}]{2}
    \Edge[lw=1, Direct](A)(2)
    \Edge[lw=1, Direct](B)(2)
\end{tikzpicture}
\end{document}

enter image description here

So all you need to do is to add style={adjust size}. As a side effect, this will then really become an ellipse if, as suggested by JouleV, once you insert a wider (or higher) text. The keys network x offset and network y offset can be thought of as the analogues of the ordinary pgf keys inner xsep and inner ysep.

Tags:

Tikz Pgf