5

I would like the draw the following diagram :
enter image description here

Here is the code I have tried :

\documentclass[tikz, border=1mm]{standalone}

\usetikzlibrary{arrows, shapes.gates.logic.US, calc}

\begin{document}
\begin{tikzpicture}
    \node (x) at (0, 1) {$x$};
    \node (y) at (0, 0) {$y$};

    \node[not gate US, draw] at ($(x) + (0.8, 0)$) (notx) {};
    \node[not gate US, draw] at ($(y) + (0.8, 0)$) (noty) {};
    \node[or gate US, draw, rotate=0, logic gate inputs=nn] at ($(noty) + (1.5, 0.5)$) (xory) {};

    \draw (x) -- (notx.input);
    \draw (y) -- (noty.input);

    \draw (notx.output) -- ([xshift=0.2cm]notx.output) |- (xory.input 1);
    \draw (noty.output) -- ([xshift=0.2cm]noty.output) |- (xory.input 2);

    \draw (xory.output) -- node[above]{$\bar x + \bar y$} ($(xory) + (1.5, 0)$);
\end{tikzpicture}
\end{document}

Here is the output:

Screenshot

But I can not able to draw what I want.

current_user
  • 5,235
WBPSC
  • 95
  • If you are trying to reproduce the image shown, you are missing quite a few components and connections. So far so good. Keep it up. – John Kormylo Sep 02 '18 at 22:20

2 Answers2

3

Just for fun, although that code I have seen in another site, I think, however, an option using nodes in the path node[pos=0.6](..., for the divergences, using path to declare the nodes in positions relative to the first gate coordinate (0,0) node... ++(2,2) node ..., then the connections using the predefined named coordinates of shapes (Nodename.input 1) and orthogonal intersections (Coordinate_A -| coordinate_B).

RESULT: enter image description here

MWE:

\documentclass[tikz, border=20pt]{standalone}
\usetikzlibrary{positioning,shapes.gates.logic.US}
\begin{document}
    \begin{tikzpicture}[
        %Environment config
        font=\sffamily,
        thick,
        %Environment styles
        GateCfg/.style={
            logic gate inputs={normal,normal,normal},
            draw,
            scale=2
        }
    ]
    \path
        (0,0) node[and gate US,GateCfg](AND1){} 
            ++ (2,-2) node[and gate US,GateCfg](AND2){} 
            ++ (5,1) node[or gate US,GateCfg](OR1){}
        (AND1.input 3)
            ++ (-1,0) node[not gate US, draw](N1){}
        (AND2.input 3)
            ++ (-1,0) node[not gate US, draw](N2){}
        (AND2.input 1 -| N1)
            node[not gate US, draw](N3){};

    \draw
        (OR1.input 1) -- ++(-1.5,0) |- (AND1.output)
        (OR1.input 3) -- ++(-1.5,0) |- (AND2.output)
        (N2.output)--(AND2.input 3)
        (N1.output)--(AND1.input 3)
        (N3.output)--(AND2.input 1)
        (AND1.input 1) 
            -- ++(-3,0) coordinate (init) node[anchor=east]{p}
            node[pos=0.6](temp){}
        (N1-| temp)
            ++(0,5pt) edge (temp.center)
            arc (90:-90:5pt) |- (N3.input)
        (init |- N1) node[anchor=east]{q} 
            -- (N1.input) node[pos=0.4](temp2){}
        (temp2.center) |- (N2.input)
        (OR1.output) -- ++(2,0) node [midway,anchor=south]{Output};
    \end{tikzpicture} 
\end{document}
J Leon V.
  • 11,533
  • 16
  • 47
0
\begin{circuitikz}
\draw
(0,0) node[nand port] (nand1) {}
(0,2) node[nand port] (nand2) {}
(2,1) node[nand port] (nand3) {}
(nand1.in 1) node[anchor=east] {A}
(nand1.in 2) node[anchor=east] {A}
(nand2.in 1) node[anchor=east] {B}
(nand2.in 2) node[anchor=east] {B}
(nand3.out) node[anchor=west] {Y}
(nand1.out) -- (nand3.in 2)
(nand2.out) -- (nand3.in 1);
\end{circuitikz}
Mensch
  • 65,388
  • 1
    I am unsure how this is supposed to be an answer to the question ... please format your answer properly and maybe add a few notes about why you think this would help the OP in reproducing the shown image. – Jasper Habicht Feb 16 '24 at 18:04