Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How would I draw this image:

enter image description here

using circuitikz?

What I have so far is

\begin{circuitikz} \draw
(0,2) node[and port] (myand) {}
(2,1) node[or port] (myor) {}
(myand.in 1) node[anchor=east] {A}
(myand.in 2) node[anchor=east] {B}
(myand.out) -| (myor.in 1)
;\end{circuitikz}

However I'm having trouble attaching the C while maintaining the alignment of A, B, and C.

share|improve this question
    
As a side note, I would suggest using circuits.logic.US library of TikZ instead. Its gates are much more beautiful. –  Ali Mehrizi May 10 '12 at 7:09

4 Answers 4

Hope the code itself is explanatory:

\documentclass{standalone}
\usepackage{circuitikz}
%
\begin{document}
\begin{circuitikz} \draw
(0,2) node[and port] (myand) {}
(2,1) node[or port] (myor) {}
(myand.in 1) node[above left=.5cm](a) {A}
(myand.in 2) node[below left = .5cm](b) {B}
(myand.out) -| (myor.in 1)
(a) -| (myand.in 1)
(b) -| (myand.in 2)
(b) node[below=1cm](c){C}
(c) -| (myor.in 2)
(c) node[draw, rectangle,inner sep=1pt,below=.5cm, right=.9cm](c){A$\cdot$B$+$C};  
\end{circuitikz}
%
\end{document}

enter image description here

share|improve this answer
    
That inner sep on the box at the bottom seems a little small. Otherwise, very nice! +1 –  qubyte May 10 '12 at 7:37
    
@MarkS.Everitt: Thanks, That is only personal preference. –  Harish Kumar May 10 '12 at 7:41
    
Of course. I couldn't find anything actually wrong with it, and couldn't just say "very nice! +1" (not enough characters). ;) –  qubyte May 10 '12 at 7:43
    
@MarkS.Everitt: Thanks a lot for your kind words. –  Harish Kumar May 10 '12 at 7:45

Here's how you can do this using \matrix.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{circuits.logic.US}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[circuit logic US,
                    line width=0.8pt,line cap=round,line join=round]

    \matrix[column sep=7mm]
    {
        \node (A) {$A$}; &                                  & & \\
                         & \node [and gate] (and1) {};      & & \\
        \node (B) {$B$}; &                                  & \node [or gate,yshift=-1mm] (or1) {}; & \node[yshift=-1mm] (out) {};\\
        \node (C) {$C$}; &                                  & & \\
    };

    \draw 
        % AND gate inputs
        (A) -- ++(right:5mm) |- (and1.input 1)
        (B) -- ++(right:5mm) |- (and1.input 2)
        % OR gate inputs
        (or1.input 1) -- ++(left:3mm) |- (and1.output)
        (or1.input 2) -- ++(left:3mm) |- (C)
        % Output
        (or1.output) -- (out);
\end{tikzpicture}

\end{document}

Result:

enter image description here

PS. If you want, you can use circuitikz's logic gates too; just replace and gate with and port and similarly for the OR gate. (But somehow circuitikz's gates are not as well-designed as those of TikZ itself, although it's other electrical elements are.)

share|improve this answer

This is another solution using the positioning library from tikz.

The main idea is to name the reference node, in this case the B node, and then just position C below that.

\documentclass{article}

\usepackage{circuitikz}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{circuitikz} \draw
(0,2) node[and port] (myand) {}
(2,1) node[or port] (myor) {}
(myand.in 1) node[anchor=east] {A}
(myand.in 2) node[anchor=east] (bnode) {B}
(myand.out) -| (myor.in 1)
node[below=of bnode] (cnode) {C}
(cnode) -| (myor.in 2)
;\end{circuitikz}

\end{document}

circuit

share|improve this answer

Another solution with TiKZ circuits library, but without matrix.

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{circuits.logic.US}

\begin{document}
\begin{tikzpicture}[circuit logic US,
                    tiny circuit symbols,
                    every circuit symbol/.style={fill=white,draw, logic gate input sep=4mm}
]

\node [and gate, inputs = nn] at (0,0) (and1) {};
\node [or gate, inputs = nn, anchor=input 1] at ($(and1.south)+(1.5cm,0)$) (or1) {};
%
\draw (and1.input 1) -- ++(left:5mm) node[left] (A) {$A$};
\draw (and1.input 2) -- ++(left:5mm) node[left] {$B$};
\node (C) at (A|-or1.input 2) {$C$};
\draw (or1.input 2) -- (C);
\draw (and1.output) -- ++(right:3mm) |- (or1.input 1);
\draw (or1.output) -- ++(right:5mm);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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