12

I found this question which suggests making a multiplexer symbol with this path:

(0,0) -- (1,-0.5) -- (1,-1.25) -- (1.3,-1.25) -- (1,-1.25)-- (1,-2) -- (0,-2.5) --
(0,-1.75) -- (-0.3,-1.75) -- (0,-1.75) -- (0,-0.75) -- (-0.3,-0.75) -- (0,-0.75) -- 
(0,0)

The answer suggests doing this to use it as a symbol:

\documentclass{article}
\usepackage{tikz}
\newcommand\multiplexer[1][1]{%
  \begin{tikzpicture}[scale=#1]
  \draw (0,0) -- (1,-0.5) -- (1,-1.25) -- (1.3,-1.25) -- (1,-1.25)-- (1,-2) -- (0,-2.5) -- (0,-1.75) -- (-0.3,-1.75) -- (0,-1.75) -- (0,-0.75) -- (-0.3,-0.75) -- (0,-0.75) -- (0,0);
  \end{tikzpicture}
}
\begin{document}
  \multiplexer[0.2]

   This is a symbol: \multiplexer
\end{document}

enter image description here

I would like to use a symbol like this as a node shape, and if possible, like that, that the inputs and outputs can easily be connected.

I saw Creating node shapes, but that requires a lot of familiarity with PGF which I don't have. Isn't there another way or a workaround to somehow use this path as a shape?

Keelan
  • 5,425
  • You may want to check: https://github.com/gsarkis/tikz-mux. This library contains handy way to draw Mux. Do you want me to give an example? – hola Mar 06 '18 at 13:41

2 Answers2

12

You can use a pic for this.

\documentclass[tikz,border=7mm]{standalone}
\usetikzlibrary{calc,quotes}
\tikzset{
  multiplexer/.pic ={
    \coordinate (-out) at (.8,0);
    \coordinate (-in-up) at (-0.8,.5);
    \coordinate (-in-down) at (-0.8,-.5);
    \draw[pic actions] (-.5,1.25) -- ++(1,-.5) -- ++(0,-1.5) -- ++(-1,-.5) --cycle;
    \draw[pic actions] (.5,0) -- (-out) (-in-up) -- +(.3,0) (-in-down) -- +(.3,0);
    \node{ \tikzpictext};
  }
}

\begin{document}
\begin{tikzpicture}
  \pic["One"] (one) {multiplexer};
  \pic[fill=red,"Two"] (two) at (-3,2) {multiplexer};
  \pic[fill=yellow,"Three"] (three) at (-3,-2) {multiplexer};
  \draw (two-out) -| (one-in-up);
  \draw (three-out) -| (one-in-down);
\end{tikzpicture}
\end{document}

enter image description here

Kpym
  • 23,002
9

There's no need to define a new shape; the shapes.geometric library already offers you the trapezium shape; with this, you can simply define a style; the already existing anchors for the trapezium can now be easily used for the in and out parts:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\tikzset{
  multiplexer/.style={
    draw,
    trapezium,
    shape border uses incircle, 
    shape border rotate=270,
    minimum size=18pt
  }  
}

\begin{document}

\begin{tikzpicture}
\node[multiplexer]
  (mul) at (0,1) {};
\draw (mul.top side) --++(10pt,0) ; 
\draw (mul.south west) --++(-10pt,0) ; 
\draw (mul.north west) --++(-10pt,0) ; 
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128