在 TikZ 电路中创建具有多个输出的逻辑电路

在 TikZ 电路中创建具有多个输出的逻辑电路

我想circuits在 TikZ 中创建具有自定义输出数量的逻辑符号库。半加器可以是此类符号的一个例子,我希望像输入一样轻松地使用它的输出(例如.output 1)。

半加器元件

此外,我希望它的输出看起来与输入相同(处于相同的水平位置等)。有什么方法可以做到这一点吗?也许有一些方法可以创建一个密钥logic gate outputs来像logic gate outputs=nn输入一样使用它?

答案1

在此处输入图片描述

\documentclass[border={10pt}]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[siunitx,european,american]{circuitikz}
\usetikzlibrary{circuits.logic.US,circuits.logic.IEC,calc}
\begin{document}
\begin{tikzpicture}
    [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        block/.style={fill=blue!20,draw=red!70,thick,minimum width=1cm,minimum height=1.5cm}
    ]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw (0,0)
  node[block, label={[label distance=-3ex]90:{\scriptsize HSUM}}] (P) {} 
  ($(P.north west)!0.4!(P.south west)$) coordinate (Pin 1)
  ($(P.north west)!0.6!(P.south west)$) coordinate (Pin 2)
  ($(P.north east)!0.4!(P.south east)$) coordinate (Pout 1)
  ($(P.north east)!0.6!(P.south east)$) coordinate (Pout 2)
  (Pin 1) to[short,-o] ++(-0.5, 0) coordinate (input1) node[left] {\tiny p1}
  (Pin 2) to[short,-o] ++(-0.5, 0) coordinate (input2) node[left] {\tiny p2}
  (Pout 1) to[short,-o] ++(0.5, 0) coordinate (output1) node[right] {\tiny p3}
  (Pout 2) to[short,-o] ++(0.5, 0) coordinate (output2) node[right] {\tiny p4}
;

\end{tikzpicture}
\end{document}

或者

正如@Rmano 在这里所描述的那样——https://tex.stackexchange.com/a/596334/197451

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\begin{document}
\begin{tikzpicture}[]
    \tikzset{ic555/.style={muxdemux,
            muxdemux def={Lh=10, NL=5, Rh=10, NR=5,
            NB=2, w=6, NT=2, square pins=1},
        no input leads, external pins width=0.4,
        circuitikz/muxdemuxes/fill=blue!10}
    }
    \node [ic555, font=\small\ttfamily,align=center](A) at (0,0) {HSUM};
    % left pins
    \foreach \rawpin/\npin/\label in {2/1/Input1, 4/2/Input2} {
        \draw (A.lpin \rawpin) -- (A.blpin \rawpin)
            node[midway, blue, font=\tiny, above]{\npin}
            node[right, font=\tiny]{\label};
    }
    % top pins
    % \foreach \rawpin/\npin in {1/8, 2/4} {
    %     \draw (A.tpin \rawpin) -- (A.btpin \rawpin)
    %         node[midway, blue, font=\small, left]{\npin};
    % }
    % bottom pins
    % \foreach \rawpin/\npin in {1/5, 2/1} {
    %     \draw (A.bpin \rawpin) -- (A.bbpin \rawpin)
    %         node[midway, blue, font=\small, left]{\npin};
    % }
    % finally, left
    \foreach \rawpin/\npin/\label in {2/3/Output1, 4/4/Output2} {
        \draw (A.rpin \rawpin) -- (A.brpin \rawpin)
            node[midway, blue, font=\tiny, above]{\npin}
            node[left, font=\tiny]{\label};
    }
    % \draw (A.rpin 3) -- (A.brpin 3) node[midway, blue, font=\small, above]{3};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容