请看下面一段代码
%%%%%%%%%%%%%%%%%%% 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}
}
它允许我编写如下命令
\draw (-4,0) node[scale=2]{\MBS{a}} ;
并生成一个中心带有标签“a”的图形(在无线通信中,这种图形指的是移动塔)。现在下面的代码
%%%%%%%%%%%%%%%%%%%%%% 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);
}}
}
允许我编写如下代码
\path (2,-1.2) pic[scale=0.5,color=red] {relay};
它会生成一个中心没有标签的图形(好奇的人可能会认为这是无线通信中的中继)。如何实现类似于第一个示例(移动塔)的中心自定义标签?
下面的代码给出了一个完整的工作示例。
\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}
答案1
像这样吗?
\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}