修复 circuitikz 逻辑电路中不美观的连接

修复 circuitikz 逻辑电路中不美观的连接

我有一个circuitikz简单的逻辑电路。虽然连接在技术上没有问题,但结果却很糟糕。我该如何改进它?

梅威瑟:

\documentclass[a4paper,12pt]{article} 
\usepackage{circuitikz}
\begin{document}
            \begin{circuitikz}
                \ctikzset{logic ports=ieee}
                \draw

                % Inputs
                (-2,2) node[left=1](X1) {$X_1$}
                (-2,1) node[left=1](X2) {$X_2$}
                (-2,0) node[left=1](X2) {$X_3$}

                % Upper OR
                (3,2) node[or port](myor1) {}
                (myor1.out) node [anchor=south west] {$x_1+x_2$}

                % NOT
                (0,0) node[not port](mynot1) {}
                (mynot1.out) node [left=10, anchor=north west] {$\overline{x_3}$}

                % Bottom OR
                (2,0) node[or port,anchor=in 2] (myor2) {}
                (myor2.out) node [anchor=north west] {$x_1 + \overline{x_3}$}

                % AND
                (5,1) node[and port,anchor=in 2] (myand1) {}
                (myand1.out) node[anchor=west] {$U$}

                % Input links
                (-2,0) -| (mynot1.in)
                (-2,1) -| (myor1.in 2)
                (-2,2) -| (myor1.in 1) to[short,*-] (myor2.in 1)

                % Other links
                (mynot1.out) -| (myor2.in 2)
                (myor2.out) -| (myand1.in 2)
                (myor1.out) -| (myand1.in 1);
            \end{circuitikz}
        \end{document}

结果: 在此处输入图片描述

答案1

这主要类似于@Archange 的回答,它会将连接的起点稍微向左移动一点,然后使用|-,但我也建议您尽可能使用相对定位。这可确保以后更容易修改,并且可重用性更高。

以下仅使用一个固定坐标(0,0),并将其他所有内容相对于该坐标进行放置。

\documentclass[a4paper,12pt]{article} 
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
  \ctikzset{logic ports=ieee}
  \draw
    % Inputs
    (0,0) node[left=1](X1) {$x_1$}
    ++(0,-1) node[left=1](X2) {$x_2$}
    ++(0,-1) node[left=1](X3) {$x_3$}

    % NOT
    (X3)++(1,0) node[not port,anchor=in](mynot1) {}
    (mynot1.out) node [left=10, anchor=north west] {$\overline{x_3}$}

    % Bottom OR
    (mynot1.out)++(1,0) node[or port,anchor=in 2] (myor2) {}
    (myor2.out) node [anchor=north west] {$x_1 + \overline{x_3}$}

    % Upper OR
    (X1-|myor2.in 1) node[or port, anchor=in 1](myor1) {}
    (myor1.out) node [anchor=south west] {$x_1+x_2$}
    ;
  % this finds the center between the two points, you could also do this using
  % the calc library instead
  \path(myor1.out)--coordinate(tmp)(myor2.out);
  \draw
    % AND
    (tmp)++(1,0)node[and port, anchor=west] (myand1){}
    (myand1.out) node[anchor=west] {$U$}

    % Input links
    (X3) -- (mynot1.in)
    (X2) -| (myor1.in 2)
    (X1) -- (myor1.in 1)
    ++(-.5,0) node[circ]{} |- (myor2.in 1)

    % Other links
    (mynot1.out) -| (myor2.in 2)
    (myor2.out) -| (myand1.in 2)
    (myor1.out) -| (myand1.in 1);
\end{circuitikz}
\end{document}

在此处输入图片描述

答案2

嗯,有一个非常简单的解决方法,但不确定这是否是你想要的:

\documentclass{standalone}

\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}
    \ctikzset{logic ports=ieee}
    \draw

    % Inputs
    (-2,2) node[left=1](X1) {$X_1$}
    (-2,1) node[left=1](X2) {$X_2$}
    (-2,0) node[left=1](X2) {$X_3$}

    % Upper OR
    (3,2) node[or port](myor1) {}
    (myor1.out) node [anchor=south west] {$x_1+x_2$}

    % NOT
    (0,0) node[not port](mynot1) {}
    (mynot1.out) node [left=10, anchor=north west] {$\overline{x_3}$}

    % Bottom OR
    (2,0) node[or port,anchor=in 2] (myor2) {}
    (myor2.out) node [anchor=north west] {$x_1 + \overline{x_3}$}

    % AND
    (5,1) node[and port,anchor=in 2] (myand1) {}
    (myand1.out) node[anchor=west] {$U$}

    % Input links
    (-2,0) -| (mynot1.in)
    (-2,1) -| (myor1.in 2)
    (-2,2) -| (myor1.in 1) to[short,*-] (myor1.in 1 |- myor2.in 1) to (myor2.in 1)

    % Other links
    (mynot1.out) -| (myor2.in 2)
    (myor2.out) -| (myand1.in 2)
    (myor1.out) -| (myand1.in 1);
\end{circuitikz}
\end{document}

输出结果如下: 第一次尝试 正如你所见,“什么输入到哪里”实际上是不可读的。

为了解决这个问题,我提前进行了分支:

\documentclass{standalone}

\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}
    \ctikzset{logic ports=ieee}
    \draw

    % Inputs
    (-2,2) node[left=1](X1) {$X_1$}
    (-2,1) node[left=1](X2) {$X_2$}
    (-2,0) node[left=1](X2) {$X_3$}

    % Upper OR
    (3,2) node[or port](myor1) {}
    (myor1.out) node [anchor=south west] {$x_1+x_2$}

    % NOT
    (0,0) node[not port](mynot1) {}
    (mynot1.out) node [left=10, anchor=north west] {$\overline{x_3}$}

    % Bottom OR
    (2,0) node[or port,anchor=in 2] (myor2) {}
    (myor2.out) node [anchor=north west] {$x_1 + \overline{x_3}$}

    % AND
    (5,1) node[and port,anchor=in 2] (myand1) {}
    (myand1.out) node[anchor=west] {$U$}

    % Input links
    (-2,0) -| (mynot1.in)
    (-2,1) -| (myor1.in 2)
    (-2,2) -| (myor1.in 1)
    (1.5,2) to[short,*-] (1.5,2 |- myor2.in 1) to (myor2.in 1)

    % Other links
    (mynot1.out) -| (myor2.in 2)
    (myor2.out) -| (myand1.in 2)
    (myor1.out) -| (myand1.in 1);
\end{circuitikz}
\end{document}

结果如下: 第二次尝试

答案3

我通常先画门,最后画输入。我改变了输入的顺序(我不知道这是否允许)。请参见下面的电路。

在此处输入图片描述

\documentclass[border=3mm]{standalone} 
\usepackage{circuitikz}
\begin{document}
            \begin{circuitikz}
                \ctikzset{logic ports=ieee}
                \draw

                % Upper OR
                (3,2) node[or port](myor1) {}
                (myor1.out) node [anchor=south west] {$x_1+x_2$}

                % Bottom OR
                (3,0) node[or port] (myor2) {}
                (myor2.out) node [anchor=north west] {$x_1 + \overline{x_3}$}
                
                % AND
                (6,1) node[and port] (myand1) {}
                (myand1.out) node[anchor=west] {$U$}
                
                % NOT
                (myor2.in 2) ++(-3,0) node[not port,anchor=in](mynot1) {}
                (mynot1.out) node [anchor=north west] {$\overline{x_3}$}


                % Input links
                (myor1.in 1) -- ++(-4,0)node[left]{$x_2$}
                (myor1.in 2) -- (myor2.in 1) node[midway](j1){}
                (j1.center) to[short,*-] ++(-4,0)node[left]{$x_1$}
                (mynot1.in 1) -- ++(-1,0)node[left]{$x_3$}
                

                % Other links
                (mynot1.out) -- (myor2.in 2)
                (myor2.out) -| (myand1.in 2)
                (myor1.out) -| (myand1.in 1);
            \end{circuitikz}
        \end{document}

相关内容