是否可以使用绘制像下面这样的自定义逻辑门circuitikz
?
或者,是否可以使用circuits.logic
库轻松地绘制它们tikz
?
答案1
这里有一个可能的解决方案。它使用trapezium
形状作为参考来绘制 ALU。
\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, positioning, calc}
\begin{document}
\begin{tikzpicture}[%
alu/.style={trapezium,
trapezium angle=30,
shape border rotate=180,
minimum width=4cm,
minimum height=3cm,
trapezium stretches=true,
append after command={%
\pgfextra
\draw (\tikzlastnode.top left corner) --
(\tikzlastnode.top right corner) --
(\tikzlastnode.bottom right corner) --
($(\tikzlastnode.bottom right corner)!.666!(\tikzlastnode.bottom side)$)--
([yshift=-8mm]\tikzlastnode.bottom side)--
($(\tikzlastnode.bottom side)!.334!(\tikzlastnode.bottom left corner)$)--
(\tikzlastnode.bottom left corner)--
(\tikzlastnode.top left corner);
\endpgfextra}},
]
\node[alu] (alu) {ADDER($n$)};
\draw (alu.south) -- ++(-90:5mm) node [below] (out) {$S[n-1:0]$};
\draw (alu.20) -- ++(0:5mm) node [right] {$C[0]$};
\draw (alu.50) -- ++(90:5mm) node [above] {$B[n-1:0]$};
\draw (alu.130) -- ++(90:5mm) node [above] {$A[n-1:0]$};
\draw (alu.130) -- ++(90:5mm) node [above] {$A[n-1:0]$};
\node[left=8mm of out] (carry) {$C[n]$};
\draw (carry) |- (alu.200);
\end{tikzpicture}
\end{document}
答案2
以下是用 circuitikz 编写的更短的解决方案,使用了 2015 年尚未提供的新功能:
\begin{circuitikz}
\node [muxdemux,
muxdemux def={NL=2, NR=1, NB=1, w=2,
inset w=1, inset Lh=2, inset Rh=0,
square pins=1, Lh=6, Rh=3}, rotate=-90](A) at (0,0)
{\rotatebox{90}{\small \ttfamily Adder(N)}};
\node[left] at (A.bpin 1) {$C[n]$};
\node[above] at (A.lpin 1) {$B[n - 1: 0]$};
\node[above] at (A.lpin 2) {$A[n - 1: 0]$};
\node[below] at (A.rpin 1) {$S[n - 1: 0]$};
\end{circuitikz}