0

The following example generates a rack switch with a single port.

The front oft the rack switch is defined by a path picture.

I add the port to path picture by using \node and i am placing the node via coodinates. Unfortunately the coordinates of the port are ignored. Instead of this the port is placed at the center oft the path picture.

Is there a general approach to place a fully defined picture like, the port, absolutely at any point inside a path picture via coordinates?

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc, shadings, shadows, shapes.arrows}
\usetikzlibrary{positioning}

\tikzset{ port/.code={% style, size, label \draw[port/rect] (0,0) rectangle (\pgfkeysvalueof{/tikz/port/tr}); \draw[fill=black] (.1cm,0cm) rectangle (.9cm,.5cm); \draw[fill=black] (.2cm,.5cm) rectangle (.8cm,.7cm); \draw[fill=black] (.4cm,.7cm) rectangle (.6cm,.8cm);
}, port/.cd, rect/.style={thin, fill=gray!20}, tr/.initial={1cm,1.5cm}, label/.initial={}, /tikz/.cd, rack switch/.style={ name=#1, fill=white, draw, minimum width=20cm, minimum height=4cm, path picture={ anchor=center; \node(port1)[port] at (-2,2){};
} } }

\begin{document} \begin{tikzpicture} \node(Switch1) at (0,0) [rack switch=switch1]{}; \end{tikzpicture}
\end{document}

Z.J
  • 389
  • Do you have a minimal example? – Z.J Aug 02 '21 at 12:24
  • 1
    Sigh, I always use \pgfdeclareshape to do this, not \tikzset. I'm sure this has come up before, but I can't figure out how to search for it. – John Kormylo Aug 02 '21 at 14:16
  • 1
    Somewhat related https://tex.stackexchange.com/questions/538051/what-is-the-simplest-possible-way-to-make-a-tikz-shape-with-ports – John Kormylo Aug 02 '21 at 14:27
  • Thank you very much for the helpful tip. There I got to know the command \ pic better and was able to solve the problem. – Z.J Aug 02 '21 at 16:42
  • My answer to https://tex.stackexchange.com/q/609368/1952 draws the whole switch as a pic with nodes inside it. I think this way is easier to control the position of elements inside the pic. – Ignasi Aug 03 '21 at 12:09

0 Answers0