# Complex circuit drawing in LaTeX How do I draw this kind of circuit?

\documentclass[12pt,a4size]{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
\node[and port, number inputs=1] (A) at (0, 0) {};
\node at (A) [ocirc] {};
\node[left] at (A.in 1) {$$x$$};
\node[left] at (A.in 2) {$$y$$};

\node[and port, number inputs=1] (B) at (0,4) {};
\node[left] at (B.in 2) {$$y$$};

\draw (A.out) -- ++ (2,0) -- ++ (0,0.28) -- ++ (0.5,0) (B.left);
\end{circuitikz}
\end{document}


This is incomplete coding. I tried as far I could. I am a beginner in circuitikz. Thanks for any help. Here's one way to do it

\documentclass{article}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
% Gates
\node[and port] (and1) at (0, 0) {};
\node[and port] (and2) at (0, -2) {};
\node[not port, scale=0.5] (not) at ($(and2.in 2) - (2, 0)$) {};
\node[or port] (or) at (4, -1) {};

% Circuit inputs
\node (in1) at ($(and1.in 1) - (3, 0)$) {};
\node (in2) at ($(and1.in 2) - (3, 0)$) {};
\node (in3) at ($(and2.in 1) - (3, 0)$) {};
\node (in4) at ($(and2.in 2) - (3, 0)$) {};

% Input wires
\draw (in1) -- (and1.in 1);
\draw (in2) -- (and1.in 2);
\draw (in3) -- (and2.in 1);
\draw (in4) -- (not.in);
\draw (not.out) -- (and2.in 2) node[midway, below] {$$z'$$};

% Input labels
\node at (in1) {$$x$$};
\node at (in2) {$$y$$};
\node at (in3) {$$y$$};
\node at (in4) {$$z$$};

% Output wires from first round of gates
\draw (and1.out) -- ++ (1, 0) |- (or.in 1) node[midway, above right] {$$xy$$};
\draw (and2.out) -- ++ (1, 0) |- (or.in 2) node[midway, below right] {$$yz'$$};

% Final output
\draw (or.out) -- ++ (1, 0) node[right] {$$xy + yz'$$};
\end{circuitikz}
\end{document}


This makes use of |- which, along with -| allow you to project out a single coordinate. That is (A |- B) has the same x coordinate as the node (A) and the same y coordinate as the node (B). Similarly (A -| B) has the same x coordinate as (B) and the same y coordinate as (A).

• I think that you can shorten your code by replacing \draw (and1.out) -- ($(and1.out) + (1, 0)$) -- ($(and1.out) + (1, 0)$) by \draw (and1.out) --++ (1, 0), with no need to use the calc library here. Apr 30, 2021 at 15:40
• Yes, you are correct. I'll change it as I think that is nicer. I just default to the calc library out of habit Apr 30, 2021 at 15:45
• Still, I don't understand why you let a redundancy. \draw (and1.out) -- ++ (1, 0) -- (and1.out) ++ (1, 0) means that you go back and forth. Why wouldn't you just use \draw (and1.out) -- ++ (1, 0)? It's no big deal, but it keeps me intrigued. Apr 30, 2021 at 15:49
• You are correct again, I've changed it Apr 30, 2021 at 15:58