1

I want to align the outputs of the ANDs (red) and write in the gates.

I use the following code:

\documentclass[border=3mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows,shapes.gates.logic.US,shapes.gates.logic.IEC,calc}
\begin{document}
\thispagestyle{empty}
\tikzstyle{branch}=[fill,shape=circle,minimum size=3pt,inner sep=0pt]
\begin{tikzpicture}[label distance=2mm]

\node (b) at (0,0) {$B$};
\node (c) at (1,0) {$C$};
\node (d) at (2,0) {$D$};

\node[and gate US, draw, logic gate inputs=nnn] at ($(d)+(2,-2)$) (and1) {};
\node[and gate US, draw, logic gate inputs=nnn] at ($(and1)+(0,-1)$) (and2) {};
\node[and gate US, draw, logic gate inputs=nnn] at ($(and2)+(0,-1)$) (and3) {};
\node[or gate US, draw, logic gate inputs=nnn, anchor=input 1] at ($(and1.output -| and2.output -| and3.output)+(1,-.8)$) (or) {};

\draw (b) |- (and2.input 1);
\draw (b) |- (and3.input 1);

\draw (c) |- (and1.input 1);
\draw (c) |- (and3.input 3);

\draw (d) |- (and1.input 3);
\draw (d) |- (and2.input 3);

\draw (and1.output) -- (or.input 1);
\draw (and2.output) -- (or.input 2);
\draw (and3.output) -- (or.input 3);

\draw (or)--++(0:1) node[right]{$S$};


\end{tikzpicture}
\end{document} 

enter image description here

enter image description here

2

To obtain the desired result to connect CD to the OR gate, you need to go hoizontal (and1.output) -- ++(0.5cm,0) and then a vertical line followed by a horizontal line via |- (or.input 1);

\draw [red, ultra thick] (and1.output) -- ++(0.5cm,0) |- (or.input 1);

and similarily for CD:

\draw [red, ultra thick] (and3.output) -- ++(0.5cm,0) |- (or.input 3);

I also correctd the output of the OR gate (not sure why it needed this correction though):

\draw [red, ultra thick] (or.east) -- ++(0.5cm,0) node [right] {$S$};

enter image description here

Notes

  • I labelled both the and gates as well as the inputs to the or gate to show you both options. Remove the one you don't want.

Code:

\documentclass[border=1mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows,shapes.gates.logic.US,shapes.gates.logic.IEC,calc}
\begin{document}
\thispagestyle{empty}
\tikzstyle{branch}=[fill,shape=circle,minimum size=3pt,inner sep=0pt]
\begin{tikzpicture}[label distance=2mm]

\node (b) at (0,0) {$B$};
\node (c) at (1,0) {$C$};
\node (d) at (2,0) {$D$};

\node[and gate US, draw, logic gate inputs=nnn, font=\bfseries\color{red}] at ($(d)+(2,-2)$) (and1) {CD};
\node[and gate US, draw, logic gate inputs=nnn, font=\bfseries\color{red}] at ($(and1)+(0,-1)$) (and2) {BD};
\node[and gate US, draw, logic gate inputs=nnn, font=\bfseries\color{red}] at ($(and2)+(0,-1)$) (and3) {BC};
\node[or gate US, draw, logic gate inputs=nnn, anchor=input 1] at ($(and1.output -| and2.output -| and3.output)+(1,-.8)$) (or) {};

\draw (b) |- (and2.input 1);
\draw (b) |- (and3.input 1);

\draw (c) |- (and1.input 1);
\draw (c) |- (and3.input 3);

\draw (d) |- (and1.input 3);
\draw (d) |- (and2.input 3);

\draw [red, ultra thick] (and1.output) -- ++(0.5cm,0) |- (or.input 1) 
        node [shift={(-0.65em,0.75ex)}, font=\tiny] {CD};
\draw [red, ultra thick] (and2.output) -- (or.input 2) 
        node [shift={(0.65em,0ex)}, , font=\tiny] {BD};
\draw [red, ultra thick] (and3.output) -- ++(0.5cm,0) |- (or.input 3) 
        node [shift={(-0.66em,-0.75ex)}, , font=\tiny] {BC};

\draw [red, ultra thick] (or.east) -- ++(0.5cm,0) node [right] {$S$};


\end{tikzpicture}
\end{document} 
3
  • Thanks for the answer, I think it doesn't look good if I write in the gates. It would be better to write the function in the outputs. How can I do? May 27 '18 at 3:42
  • Check the second image please May 27 '18 at 3:46
  • See update solution. Both options provided. May 27 '18 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.