我怎样才能使我的逻辑电路看起来“更好”?

我怎样才能使我的逻辑电路看起来“更好”?

我是新手,我正在尝试使用 circuiTikz 绘制逻辑图,但不太正确,

在此处输入图片描述

我能做些什么来避免线路在不应该合并时合并?另外,有什么方法可以将节点 X 与 R 门中的第一个条目对齐?

顺便说一下,代码如下:

\begin{tikzpicture} 
\ctikzset{
    logic ports=ieee,
    logic ports/scale=0.6,
}

\draw

node[not port] (not1) at  (4,7.5) {}
node[not port] (not2) at  (4,6.5) {}
node[not port] (not3) at  (4,5.5) {}

node[nor port, number inputs=3] (norR) at (6,8) {R}
node[nor port] (norS) at (6,6) {S}
node[and port] (andT) at (6,4) {T}

node[or port, number inputs = 3] (orF) at  (8,6) {}

node[] (X) at (2,8.25) {X}
node[] (Y) at (2,4.25) {Y} 
node[] (Z) at (2,3.75) {Z}
node[] at (8.75,6) {F}

(not1) -| (norR.in 2)
(not2) -| (norR.in 3)
(not2) -| (norS.in 1)
(not3) -| (norS.in 2)
(norR.out) -| (orF.in 1)
(norS.out) -| (orF.in 2)
(andT.out) -| (orF.in 3)

(X) -| (norR.in 1)
(X) -| (not3.in)

(Y) -| (andT.in 1)
(Y) -| (not1.in)

(Z) -| (andT.in 2)
(Z) -| (not2.in)

;
\end{tikzpicture}

答案1

@js-bibra 回答是一种减少纠结的优雅方法,所以去做吧,除非你希望输入严格在左边。

不过,我将发布对您的代码的修改,以展示如何进行最小的修改以使图表更清晰,以及如何“交错”电缆以避免覆盖垂直电缆。

诀窍是尽可能使用相对坐标,垂直坐标,然后“放大”一点,输入会导致一些输入。我在代码中注释了...

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\begin{document}

\begin{tikzpicture}
\ctikzset{
    logic ports=ieee,
    logic ports/scale=0.6,
}

\draw

node[not port] (not1) at  (4,7.5) {}
node[not port] (not2) at  (4,6.5) {}
node[not port] (not3) at  (4,5.5) {}

node[nor port, number inputs=3] (norR) at (6,8) {R}
node[nor port] (norS) at (6,6) {S}
node[and port] (andT) at (6,4) {T}

node[or port, number inputs = 3] (orF) at  (8,6) {}

% use relative coordinates here, to align with port inputs

node[] (X) at ([xshift=-4cm] norR.in 1) {X}
node[] (Y) at (X|-andT.in 1) {Y}  % in the same place vertical as X!
node[] (Z) at (X|-andT.in 2) {Z}
node[right] at (orF.out) {F}

% not output connections (reverse for staggering, use .out anchor!)
(norR.in 2) --++(-0.5,0) |- (not1.out)
(norR.in 3) |- (not2.out)
(norS.in 1) |- (not2.out)
(norS.in 2) |- (not3.out)

(norR.out) -| (orF.in 1)
(norS.out) -| (orF.in 2)
(andT.out) -| (orF.in 3)

% connection the other way around to easily "stagger" them

(norR.in 1) |- (X)
(not3.in) |- (X)

(andT.in 1) |- (Y)
(not1.in)   --++(-0.5,0) |- (Y)

(andT.in 2) |- (Z)
(not2.in) -- ++(-1,0) |- (Z)

;
\end{tikzpicture}
\end{document}

在此处输入图片描述

无论如何,让我提出另一种变化。我喜欢使用输入轨当有多个变量时,为了使连接容易跟踪,并在连接它们时添加点(即使它们不是严格需要的,它们也会突出显示连接并清楚地表明裸露的交叉点就是交叉点)。

我也使用多个\draw命令,以便能够使用宏来简化事情并轻松创建循环。

在此处输入图片描述

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}

\newcommand{\gotorail}[2]{\draw (#1) to[short,-*] (#1 -| #2);}

\begin{document}

\begin{tikzpicture}
\ctikzset{
    logic ports=ieee,
    logic ports/scale=0.6,
}

\draw
node[not port] (not1) at  (4,7.5) {}
node[not port] (not2) at  (4,6.5) {}
node[not port] (not3) at  (4,5.5) {}
node[nor port, number inputs=3] (norR) at (6,8) {R}
node[nor port] (norS) at (6,6) {S}
node[and port] (andT) at (6,4) {T}
node[or port, number inputs = 3] (orF) at  (8,6) {};

% input rails
\coordinate (rail) at ([xshift=-5cm, yshift=0.5cm] norR.north);
\foreach [count=\i] \n in {X, Y, Z} {
    \path (rail) ++({\i/2},0) node[above](\n){\n};
    \draw (\n) -- (\n |- andT.south);
}

% output
\node[right] at (orF.out) {F};

% not output connections
\draw
(norR.in 2) --++(-0.5,0) |- (not1.out)
(norR.in 3) |- (not2.out)
(norS.in 1) |- (not2.out)
(norS.in 2) |- (not3.out)
;

% port connections
\draw
(norR.out) -| (orF.in 1)
(norS.out) -| (orF.in 2)
(andT.out) -| (orF.in 3)
;
% connection the other way around to easily "stagger" them

% input rail connection
\gotorail{norR.in 1}{X}
\gotorail{not3.in}{X}

\gotorail{andT.in 1}{Y}
\gotorail{not1.in}{Y}

\gotorail{andT.in 2}{Z}
\gotorail{not2.in}{Z}

\end{tikzpicture}
\end{document}

答案2

在此处输入图片描述

\documentclass[10pt,a4paper]{article}

\usepackage{circuitikz}
\usetikzlibrary{positioning, calc}

\begin{document}
    \begin{tikzpicture} 
        \ctikzset{
            logic ports=ieee,
            logic ports/scale=0.6,
        },
        \tikzset{
            between/.style args={#1 and #2}{
                at = ($(#1)!0.5!(#2)$)
            }
        }
        \draw
        node[nor port, number inputs=3] at (6,7.5) (norR)  {R}
        node[nor port, below=of norR] (norS)  {S}
        node[and port, below=of norS] (andT)  {T}
        
        coordinate[between=norR.in 3 and norS.in 1] (aux) {}
        
        node[not port, left=2cm of aux] (not2) {}
        node[not port, left=2cm of norR.in 2] (not1) {}
        node[not port, left=2cm of norS.in 2] (not3) {}
%       
        node[or port, number inputs = 3, right=of norS] (orF)  {}
%%      
        node[left=2cm of not3] (Y) {Y} 
        node[right=1mm of Y] (Z)  {Z}
        node[right=1mm of Z] (X)  {X}
        node[right=1mm of orF]   {F}
%%      
        (not1) -| (norR.in 2)
        (not2) -| (norR.in 3)
        (not2) -| (norS.in 1)
        (not3) -| (norS.in 2)
        (norR.out) -| (orF.in 1)
        (norS.out) -| (orF.in 2)
        (andT.out) -| (orF.in 3)
%       
        (X)--++(0,2.5cm) -| (norR.in 1)
        (X) |- (not3.in)
%       
        (Y) |- (andT.in 1)
        (Y) |- (not1.in)
%       
        (Z) |- (andT.in 2)
        (Z) |- (not2.in)
%       
        ;
    \end{tikzpicture}
\end{document}

相关内容