1

I am trying to make a diagram of a mobile network. For this purpose I have created a base station/cell tower drawing in tikz.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}

\foreach \x in {-0.75, -0.25, 0.25, 0.75} {
    \draw[thick] (\x,0) -- (\x,0.5);
}

\draw[thick] (-0.75,0) -- (0.75,0);

\path[name path=left, draw, thick] (-0.75, -3) -- (-0.0625, 0);
\path[name path=right, draw, thick] (0.75, -3) -- (0.0625, 0);

\path[name path=int1] (-1, -0.625) -- (1, -0.625);
\path[name path=int2] (-1, -1.5) -- (1, -1.5);
\path[name path=int3] (-1, -2.5) -- (1, -2.5);

\path[name intersections={of=int1 and left,by=li1}];
\path[name intersections={of=int2 and left,by=li2}];
\path[name intersections={of=int3 and left,by=li3}];

\path[name intersections={of=int1 and right,by=ri1}];
\path[name intersections={of=int2 and right,by=ri2}];
\path[name intersections={of=int3 and right,by=ri3}];

\draw (li1) -- (ri1);
\draw (li2) -- (ri2);
\draw (li3) -- (ri3);
\draw (li1) -- (ri2);
\draw (li2) -- (ri1);
\draw (li2) -- (ri3);
\draw (li3) -- (ri2);


\end{tikzpicture}
\end{document}

enter image description here

Is there a way to use a tikz picture as a shape for a node so I can place it easily in a bigger diagram?

3
  • You can nest a tikzpicture inside a node in another tikzpicture using \node {\begin{tikzpicture} ... \end{tikzpicture}};
    – vi pa
    Nov 16, 2019 at 11:40
  • @vipa I wouldn't generally recommend that. While it can work, it can also cause unexpected problems due to inheritance of options. It's also usually unnecessary. Searching for nesting tikzpictures here on the site will lead to several questions about this. Nov 16, 2019 at 13:26
  • @TorbjørnT. I must admit that is not an elegant solution. The Schr.'s cat solution is better.
    – vi pa
    Nov 16, 2019 at 20:44

1 Answer 1

3

Welcome! Yes, of course you can make this a pic. You do not need intersections for this either.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[pics/power pole/.style={code={
 \draw[thick] \foreach \X in {0.25, 0.75} {(-\X,0.5) |- (\X,0) -- (\X,0.5)}
    (-0.75, -3) -- (-0.0625, 0) coordinate[pos=0.175] (l3)
        coordinate[pos=0.5] (l2) coordinate[pos=0.775] (l1)
    (0.75, -3) -- (0.0625, 0) coordinate[pos=0.175] (r3)
        coordinate[pos=0.5] (r2) coordinate[pos=0.775] (r1);
  \draw (l1) -- (r1) (l2) -- (r2) (l3) -- (r3)
  (l1) -- (r2) (l2) -- (r3) (l3) -- (r2) (l2) -- (r1);
}}]

\path  pic{power pole};
\end{tikzpicture}
\end{document}

enter image description here

1
  • Thank you for this simple solution, as a beginner I sometimes can't see the forest for the trees! Nov 19, 2019 at 12:38

You must log in to answer this question.

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