我发现这这个问题建议用这个路径制作多路复用器符号:
(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)
答案建议这样做以将其用作符号:
\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}
我想使用这样的符号作为节点形状,如果可能的话,这样输入和输出就可以轻松连接。
我看见创建节点形状,但这需要非常熟悉 PGF,而我并不熟悉。有没有其他方法或变通方法可以以某种方式将此路径用作形状?
答案1
没有必要定义新的形状;shapes.geometric
库已经为您提供了trapezium
形状;通过这个,您可以简单地定义一种样式;现在可以轻松地将现有的梯形锚点用于进出部分:
\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}
答案2
您可以使用pic
来实现这一点。
\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}