我必须使用 Latex 绘制一个与图片完全相同的 8:1 多路复用器。
我关注了关联但我无法使其适应我的图像(链接和重命名输入)。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0,0)coordinate (O)--++(30:1)coordinate (A)--++(90:4)coordinate (B)--++(150:1)coordinate (C)--cycle;
\draw ($(A)!0.5!(B)$)--++(0:1)node[right]{$F$};
\draw ($(O)!0.5!(A)$)--++(-90:1)--++(180:2)node[left]{$b$};
\draw ($(O)!0.25!(A)$)--++(-90:0.5)--++(180:1.75)node[left]{$a$};
\draw ($(O)!0.75!(A)$)--++(-90:1.5)--++(180:2.25)node[left]{$c$};
\foreach \y/\t in {0.1/1,0.2/2,0.3/3,0.4/4,0.5/5,0.6/6,0.7/7,0.8/8} {
\draw ($(C)! \y*1.1 !(O)$)--++(180:1) node[left] {$I \t$};}
\end{tikzpicture}
\end{document}
答案1
这是一个使用pic
\documentclass[border = 5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
multiplexer/.pic = {
% frame
\draw[pic actions] (0, 0) coordinate (-SW) -- ++(30 : 1.5)
coordinate (-SE) -- ++(90 : 4) coordinate (-NE) -- ++(150 : 1.5)
coordinate (-NW) -- cycle;
% output
\coordinate (-output) at ($(-SE)!0.5!(-NE)$);
% select
\foreach \x/\lbl in {0.25/A,0.50/B,0.75/C} {
\coordinate (-\lbl) at ($(-NW)!\x!(-NE)$);
}
% input
\pgfmathsetmacro{\ymin}{1.0}
\pgfmathsetmacro{\ymax}{4.5}
\foreach \i in {0,1} {
\foreach \j in {0,1} {
\foreach \k in {0,1} {
\pgfmathsetmacro{\y}{\ymax - (\ymax - \ymin) * (\k + 2*\j + 4*\i)/7.};
\coordinate (-\i\j\k) at (0,\y);
\node[xshift = 8pt] at (-\i\j\k) {$\i\j\k$};
}
}
}
}
}
\begin{document}
\begin{tikzpicture}
\pic(multi) [draw, fill = blue!20] {multiplexer};
% select
\coordinate (T) at ([yshift = 5pt]multi-NW);
\foreach \s in {A,B,C}
\draw (multi-\s) -- (multi-\s |- T) node[above]{$\s$};
% ground
\coordinate (G) at (-1, 5);
\draw[cyan] ([xshift = -3pt]G) -- ([xshift = 3pt]G);
\foreach \n in {000,011,100,101} \draw[cyan] (multi-\n) -| (G);
% in
\coordinate (I) at (-0.5, 0);
\draw[black] ([xshift = -3pt]I) -- ([xshift = 3pt]I) -- ([yshift =
-5pt]I) -- cycle;
\foreach \n in {001,010,110,111} \draw[black] (multi-\n) -| (I);
% output
\draw (multi-output) -- ++(0:0.5) node[right]{$Y$};
\end{tikzpicture}
\end{document}