# How to draw logic gates in tikz

I would like the draw the following diagram : 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: But I can not able to draw what I want.

• 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 2 '18 at 22:20

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).

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}