3

Please look at the following piece of code

%%%%%%%%%%%%%%%%%%% MOBILE TOWER %%%%%%%%%%%%%%%%%%%%%
\newcommand{\MBS}[1]{%
\begin{tikzpicture}[]
\node[station] (base) {#1};

%\draw[line join=bevel] (base.110) -- (base.70) -- (base.north west) -- (base.north east) -- cycle;
\draw[line join=bevel] (base.100) -- (base.80) -- (base.110) -- (base.70) -- (base.north west) -- (base.north east);
\draw[line join=bevel] (base.100) -- (base.70) (base.110) -- (base.north east);

% original yshift=.8pt
%\draw[line cap=rect] ([xshift=.5cm,yshift=.3pt] base.north) [antenna=1];
%\draw[line cap=rect] ([yshift=.3pt]ant1 |- base.north) -- node[above,shape=rectangle,inner ysep=+.3333em]{\dots} ([xshift=-.5cm,yshift=.3pt]base.north) [antenna=2];
\draw[line cap=rect] ([xshift=-.1768cm,yshift=.6pt]base.north -| base.right tail) [antenna=1];
\draw[line cap=rect] ([yshift=.6pt]ant1 |- base.north) -- node[above,shape=rectangle,inner ysep=+.3333em]{\dots} ([xshift=.1768cm,yshift=.6pt]base.north -| base.left tail) [antenna=2];

%\draw[line cap=rect] ([yshift=.3pt]ant1 |- base.north) -- ([xshift=-.5cm,yshift=.3pt]base.north) [antenna=2];
%\node at ($(ant1)!0.5!(ant2)$) {\dots};
\end{tikzpicture}
}

It allows me to write commands like

\draw (-4,0) node[scale=2]{\MBS{a}} ;

and generate a figure with a label 'a' in its centre (In wireless communications, this diagram sort of refers to a mobile tower). Now the following piece of code

%%%%%%%%%%%%%%%%%%%%%% RELAY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{radiation/.style={{decorate,decoration={expanding waves,angle=90,segment length=4pt}}},
         relay/.pic={
        code={\tikzset{scale=5/10}
            \draw[semithick] (0,0) -- (1,4);% left line
            \draw[semithick] (3,0) -- (2,4);% right line
            \draw[semithick] (0,0) arc (180:0:1.5 and -0.5);
            \node[inner sep=4pt] (circ) at (1.5,5.5) {};
            \draw[semithick] (1.5,5.5) circle(8pt);
            \draw[semithick] (1.5,5.5cm-8pt) -- (1.5,4);
            \draw[semithick] (1.5,4) ellipse (0.5 and 0.166);
            \draw[semithick,radiation,decoration={angle=45}] (1.5cm+8pt,5.5) -- +(0:2);
            \draw[semithick,radiation,decoration={angle=45}] (1.5cm-8pt,5.5) -- +(180:2);
  }}
}

allows me to write code like

\path (2,-1.2)  pic[scale=0.5,color=red] {relay};

which generates a figure without a label at its center (For the curious, it is referred to as a relay in wireless communications). How do I achieve that custom labeling in the center similar to the first example (mobile tower).

A full working example is given in the following code.

\documentclass[tikz]{standalone}
   \usepackage{ellipsis}
   \usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,shapes.geometric}
\tikzset{naming/.style={align=center,font=\small}}
\tikzset{antenna/.style={insert path={-- coordinate (ant#1) ++(0,0.25) -- +(135:0.25) + (0,0) -- +(45:0.25)}}}
\tikzset{station/.style={naming,draw,shape=dart,shape border rotate=90, minimum width=10mm, minimum height=10mm,outer sep=0pt,inner sep=3pt}}
%\tikzset{mobile/.style={naming,draw,shape=rectangle,minimum width=15mm,minimum height=7.5mm, outer sep=0pt,inner sep=3pt}}
\tikzset{mobile/.style={naming,draw,shape=rectangle,minimum width=12mm,minimum height=6mm, outer sep=0pt,inner sep=3pt}}
%\tikzset{radiation/.style={{decorate,decoration={expanding waves,angle=90,segment length=4pt}}}}

%%%%%%%%%%%%%%%%%%%%%% RELAY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{radiation/.style={{decorate,decoration={expanding waves,angle=90,segment length=4pt}}},
         relay/.pic={
        code={\tikzset{scale=5/10}
            \draw[semithick] (0,0) -- (1,4);% left line
            \draw[semithick] (3,0) -- (2,4);% right line
            \draw[semithick] (0,0) arc (180:0:1.5 and -0.5);
            \node[inner sep=4pt] (circ) at (1.5,5.5) {};
            \draw[semithick] (1.5,5.5) circle(8pt);
            \draw[semithick] (1.5,5.5cm-8pt) -- (1.5,4);
            \draw[semithick] (1.5,4) ellipse (0.5 and 0.166);
            \draw[semithick,radiation,decoration={angle=45}] (1.5cm+8pt,5.5) -- +(0:2);
            \draw[semithick,radiation,decoration={angle=45}] (1.5cm-8pt,5.5) -- +(180:2);
  }}
}

%%%%%%%%% MOBILE PHONE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\UE}[1]{%
\begin{tikzpicture}[every node/.append style={rectangle,minimum width=0pt}]
\node[mobile] (box) {#1};

\draw ([xshift=.25cm] box.south west) circle (4pt)
      ([xshift=-.25cm]box.south east) circle (4pt);

\fill ([xshift=.25cm] box.south west) circle (1pt)
      ([xshift=-.25cm]box.south east) circle (1pt);

\draw (box.north) [antenna=1];
\end{tikzpicture}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MOBILE BASE STATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\MBS}[1]{%
\begin{tikzpicture}[]
\node[station] (base) {#1};

%\draw[line join=bevel] (base.110) -- (base.70) -- (base.north west) -- (base.north east) -- cycle;
\draw[line join=bevel] (base.100) -- (base.80) -- (base.110) -- (base.70) -- (base.north west) -- (base.north east);
\draw[line join=bevel] (base.100) -- (base.70) (base.110) -- (base.north east);

% original yshift=.8pt
%\draw[line cap=rect] ([xshift=.5cm,yshift=.3pt] base.north) [antenna=1];
%\draw[line cap=rect] ([yshift=.3pt]ant1 |- base.north) -- node[above,shape=rectangle,inner ysep=+.3333em]{\dots} ([xshift=-.5cm,yshift=.3pt]base.north) [antenna=2];
\draw[line cap=rect] ([xshift=-.1768cm,yshift=.6pt]base.north -| base.right tail) [antenna=1];
\draw[line cap=rect] ([yshift=.6pt]ant1 |- base.north) -- node[above,shape=rectangle,inner ysep=+.3333em]{\dots} ([xshift=.1768cm,yshift=.6pt]base.north -| base.left tail) [antenna=2];

%\draw[line cap=rect] ([yshift=.3pt]ant1 |- base.north) -- ([xshift=-.5cm,yshift=.3pt]base.north) [antenna=2];
%\node at ($(ant1)!0.5!(ant2)$) {\dots};
\end{tikzpicture}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%% DIAGRAM STARTS HERE %%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}%[every path/.append style={thick}]
\draw (-4,0) ellipse (8 and 3);
\draw (8,0) ellipse (8 and 3);

\draw (-4,0) node[scale=2]{\MBS{a}} ;
\draw (8,0) node[scale=2,color=red]{\MBS{2}} ;
\path (2,1)  pic[scale=0.5,color=red] {relay};
\path (2,-1.2)  pic[scale=0.5,color=red] {relay};
\draw (1,0) node[scale=.8]{\UE{1}};
\draw (-1,0) node[scale=.8]{\UE{2}};
\end{tikzpicture}
\end{document}
  • Please, provide a complete working example, from \documentclass to \end{document} with all libraries and definitions. You first code doesn't work because station is not defined. – Ignasi Feb 17 '15 at 11:28
3

Something like this?

enter image description here

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{decorations.pathreplacing}


\tikzset{radiation/.style={{decorate,decoration={expanding waves,angle=90,segment length=4pt}}},
         relay/.pic={
        code={\tikzset{scale=5/10}
            \draw[semithick] (0,0) -- (1,4);% left line
            \draw[semithick] (3,0) -- (2,4);% right line
            \draw[semithick] (0,0) arc (180:0:1.5 and -0.5) node[above, midway]{#1};
            \node[inner sep=4pt] (circ) at (1.5,5.5) {};
            \draw[semithick] (1.5,5.5) circle(8pt);
            \draw[semithick] (1.5,5.5cm-8pt) -- (1.5,4);
            \draw[semithick] (1.5,4) ellipse (0.5 and 0.166);
            \draw[semithick,radiation,decoration={angle=45}] (1.5cm+8pt,5.5) -- +(0:2);
            \draw[semithick,radiation,decoration={angle=45}] (1.5cm-8pt,5.5) -- +(180:2);
  }}
}

\begin{document}

\begin{tikzpicture}
\path (2,-1.2)  pic[scale=0.5,color=red] {relay=B};
\end{tikzpicture}

\end{document}
|improve this answer|||||
  • Thanks. But when I change the scale, the font scale doesn't change. – dineshdileep Feb 18 '15 at 7:21
  • @dineshdileep By default, font size is not affected with scale factors. You can change this behavior applying transform shape option to those nodes where you want to change it. – Ignasi Feb 18 '15 at 8:00
  • How do I do that in the above code? I added "tranform shape" to both \tikzset code and in the code between \begin{document}\end{document}. But it is not working. My tikz skills are at beginner level. I apologize. – dineshdileep Feb 18 '15 at 8:31
  • @dineshdileep node[transform shape, above, midway]{#1} That's all. But remember that a previous scale=5/10 has been already applied when watching results. – Ignasi Feb 18 '15 at 8:35
  • I changed that to scale=10/10. But not giving satisfactory results. Is there a way to scale the font alone? – dineshdileep Feb 18 '15 at 8:43

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.