This is related to wireless sensor networks. Can anyone please help?
-
1Hi, and welcome to TeX.sx. Can you show us what you have already tried (as a complete, compilable code example) and describe what your problems are? That makes it easier for us to help you.– FritzNov 14, 2019 at 9:39
-
This is not a simple figure, need to write some lines of codes to achieve it...– MadyYuviNov 21, 2019 at 12:42
Add a comment
|
1 Answer
As starting point:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 0pt,
box/.style = {draw, fill=#1, align=center,
text width=5em, text height=2ex, text depth=0.25ex,
outer sep=0pt}
]
\draw[thick] (0,0) node (n1) [above left] {Sender} -- ++ (7,0);
\node (n2) [box=green,above] at (3.5,0) {packet};
%
\draw[thick] (0,-1) node (n3) [above left] {Receiver} -- ++ (7,0);
\node (n4) [box=green,above] at (3.5,-1) {packet};
\node (n5) [box=red, left=of n4] {idle};;
\node (n6) [box=red, right=of n4] {idle};;
\end{tikzpicture}
% second example
\begin{tikzpicture}[
node distance = 0pt,
box/.style = {draw, fill=#1, align=center,
text width=5em, text height=2ex, text depth=0.25ex,
outer sep=0pt}
]
\draw[thick] (0,0) node (n1) [above left] {Sender A} -- ++ (7,0);
\node (n2) [box=green,above] at (2,0) {packet};
%
\draw[thick] (0,-1) node (n3) [above left] {Sender B} -- ++ (7,0);
\node (n4) [box=green,above] at (3,-1) {packet};
%
\draw[thick] (0,-2) node (n5) [above left] {Receiver} -- ++ (7,0);
\scoped[text=white]
{
\node (n6) [box=green, above] at (2,-2) {packet};
\node (n4) [box=red,above] at (3,-2) {garbage};
}
\end{document}
Edit: For exercise is added one more example.