5

I'm trying to draw networks like network in the figure below. I can draw similar networks using tokens, nodes and edges but the problem is that I can only connect nodes by edges.

What I need is to connect tokens inside nodes by edges like the figure below: (In this example, node R has two tokens. One of them is connected to node A and the other is connected to node B.)

Is it possible to achieve this using Tikz?

network

Here is what I tried so far:

\begin{tikzpicture}[node distance=1.5cm] 
\begin{scope} 
\node [place,tokens=1](0)[label=below:$A$]{}; 
\node [place,tokens=2] (1) [right of=0,label=below:$R$] {} edge (0); 
\node [place,tokens=1] (2) [right of=1,label=below:$B$] {} edge (1); 
\end{scope} 
\end{tikzpicture} 
2
  • 2
    welcome to tex.se! yes, it is possible to draw this figure :-). what you try so far? please show us this!
    – Zarko
    Nov 28, 2018 at 22:43
  • Thanks :) Here is what I tried so far: \begin{tikzpicture}[node distance=1.5cm] \begin{scope} \node [place,tokens=1](0)[label=below:$A$]{}; \node [place,tokens=2] (1) [right of=0,label=below:$R$] {} edge (0); \node [place,tokens=1] (2) [right of=1,label=below:$B$] {} edge (1); \end{scope} \end{tikzpicture}
    – itechi
    Nov 28, 2018 at 22:45

2 Answers 2

7

One of many possible methods:

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, fit}
\begin{document}
\begin{tikzpicture}[
  dot/.style={fill,circle, minimum size=5pt,inner sep=0,node contents={}},
  circ/.style={draw, circle, minimum size=10pt,inner sep=0pt, node contents={}}
]

\node [dot, name=n1];
\node [dot, name=n2, right=of n1];
\node [dot, name=n3, right=5mm of n2];
\node [dot, name=n4, right=of n3];

\draw (n1) -- (n2) (n3) -- (n4);

\node [circ,fit=(n2)(n3), label={[name=R]below:R}];
\node [circ, left, at=(n1.east), name=A];
\node [circ, right, at=(n4.west), name=B];

\node at (A |- R) {A};
\node at (B |- R) {B};
\end{tikzpicture}
\end{document}
6

Simply using the arrows.meta library, the Circle tip can be used and customized as you want, e.g, >={Circle[length=5pt]}, shorten >= -5pt, shorten <= -5pt will use a 5pt filled circle and will also lengthen the line by the same amount in both sides. If you want the tip touch the circle from inside, just subtract another \pgflinewidth from the above.

\documentclass[tikz,12pt]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}

\begin{tikzpicture}[>={Circle[length=5pt]}, shorten >= -5pt-\pgflinewidth, shorten <= -5pt-\pgflinewidth]

\node(a) at (0,0) [draw,circle,minimum size=.5cm]{};
\node(r) at (2,0) [draw,circle,minimum size=1cm]{};
\node(b) at (4,0) [draw,circle,minimum size=.5cm]{};

\node at ([yshift=-2em]a) {A};
\node at ([yshift=-2em]r) {R};
\node at ([yshift=-2em]b) {B};

\draw[<->] (a) -- (r);
\draw[<->] (r) -- (b);

\end{tikzpicture}

\end{document

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .