使用 Circuitikz 绘制逻辑门

使用 Circuitikz 绘制逻辑门

我想画出逻辑电路,但是遇到了一些问题。这是我的示例代码。

\begin{figure}[!htb]
    \centering
    \begin{circuitikz}[/tikz/circuitikz/bipoles/length=1cm]
\draw

(0,2)   node (myand1) [and port]{}
(myand1.out)  node (Y1)[anchor=south west]  {$A \cdot B$}
(myand1.in 1) node (A1)     [anchor=east,xshift=-1cm]{A}
(myand1.in 2) node (B1)     [anchor=east,xshift=-1cm]{B} 

(0,1)         node (mynot1) [not port] {} 
(mynot1.out)  node (Ybar)    [anchor=south west]   {}

(2,0)   node (myand2) [and port]{}
(myand2.out)  node (Y2)[anchor=south west,xshift=0.5cm,yshift=-0.5cm]  {$\overline{B} \cdot A$}
(myand2.in 1) node (B2) [anchor=south east]   {$\overline{B}$}


(4,1)   node (myor3) [or port]{}
(myor3.out)  node (Y3)[anchor=south west]  {$A \cdot B + \overline{B} \cdot A$};

%draw line
\draw (myand1.in 1) -- (A1);
\draw (myand1.in 2) -- (B1);
\draw (myand1.in 2) |- (mynot1.in);
\draw (mynot1.out) |- (myand2.in 1) ;

\draw (myand2.out) -| (myor3.in 2);
\draw (myand1.out) -| (myor3.in 1);
\node (Ah1)[xshift=1cm] at (A1) {$\bullet$};
\node at (myand1.in 2) {$\bullet$};
\draw (Ah1) |- (myand2.in 2);

\foreach \Point in {(A1),(B1)}{
    \node [xshift=.2cm] at \Point {$\bullet$};
}


    \end{circuitikz}
    \caption{วงจรลองจิกตามสมการ $X = A \cdot B + B \cdot A$}
    \label{fig:exampleLogic}
\end{figure}

这是我的结果。

在此处输入图片描述

第二个与门的输入线没有连接到输入 A。我尝试使用代码创建节点名称 Ah1\node (Ah1)[xshift=1cm] at (A1) {$\bullet$};来制作节点。我用 画了一条线\draw (Ah1) |- (myand2.in 2);。但是,线没有连接到Ah1节点。

提前感谢您的建议。

答案1

绘图可以进一步简化,但这里的主要问题是尝试使用带有 的节点$\bullet$作为连接点(行话中称为“极点” )。构建节点时,内容和绘图的其余部分之间circuitikz有一个分隔( ),并且inner sep这就是你看到的差距。因此,最好的办法是使用提供的方法node[circ](name){}来添加点...

最小的变化如下:

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\begin{document}
\begin{circuitikz}[circuitikz/bipoles/length=1cm, circuitikz/logic ports=ieee]
    \draw

    (0,2)   node (myand1) [and port]{}
    (myand1.out)  node (Y1)[anchor=south west]  {$A \cdot B$}
    (myand1.in 1) -- ++(-1,0) node[circ](A1){} node[left]{$A$}
    (myand1.in 2) -- ++(-1,0) node[circ](B1){} node[left]{$B$}

    (0,1)         node (mynot1) [not port]{}
    (mynot1.out)  node (Ybar)   [anchor=south west]{}

    (2,0)   node (myand2) [and port]{}
    (myand2.out)  node (Y2)[anchor=south west,xshift=0.5cm,yshift=-0.5cm]  {$\overline{B} \cdot A$}
    (myand2.in 1) node (B2) [anchor=south east]   {$\overline{B}$}

    (4,1)   node (myor3) [or port]{}
    (myor3.out)  node (Y3)[anchor=south west]  {$A \cdot B + \overline{B} \cdot A$};

    %draw line
    \draw (myand1.in 2) node[circ]{} |- (mynot1.in);
    \draw ([xshift=-0.5cm]myand1.in 1) node[circ]{} |- (myand2.in 2);
    \draw (mynot1.out) |- (myand2.in 1) ;

    \draw (myand2.out) -| (myor3.in 2);
    \draw (myand1.out) -| (myor3.in 1);

\end{circuitikz}
\end{document}

在此处输入图片描述

相关内容