2

I'd like to draw this with LaTeX:

enter image description here


This is what I have so far:

enter image description here

%%%%%PREAMBLE%%%%%
\documentclass[border=0.25cm]{standalone}
\usepackage{circuitikz}

%%%%%HEAD%%%%%
\begin{document}
    \begin{circuitikz}

        %%%%%OBJECTS%%%%%
        \draw (-3.50,-3.00) -- ++(0,3.50) node[above] (x) {\(x\)};
        \draw (-2.50,-3.00) -- ++(0,3.50) node[above] (y) {\(y\)};
        \draw (-1.50,-3.00) -- ++(0,3.50) node[above] (z) {\(z\)};
        %%%%%%%%%%%%%%%%%
        \draw (+0.67,-1.00) node[and port] (and2){};
        \draw (+4.50,-1.00) node[and port] (and1){};
        \draw (+0.00,-2.50) node[not port] (not2){};
        \draw (+2.50,-1.75) node[or port]  (orr1){};

        %%%%%INPUTS%%%%%%
        \draw[fill] (and1.in 1) -- (x |- and1.in 1) circle (1pt);
        \draw[fill] (and2.in 2) -- (y |- and2.in 2) circle (1pt);
        \draw[fill] (not2.in)   -- (y |- not2.in)   circle (1pt);
        \draw[fill] (and2.in 1) -- (z |- and2.in 1) circle (1pt);
        %%%%%%%%%%%%%%%%%
        \draw       (and2.out)  -- (orr1.in 1);
        \draw       (not2.out)  -- (orr1.in 2);
        \draw       (orr1.out)  -- (and1.in 2);

        %%%%%OUTPUT%%%%%%
        \draw (and1.out) node[right=0.63cm](M){$M$};
        \draw (and1.out) -- (M);

%%%%%TAIL%%%%%
    \end{circuitikz}
\end{document}

Obviously, I could just shift an AND gate, so they aren't directly parallel, but absolute control over the output would be preferable.

Also, it would be nice if I could get the AND and NOT gates to line up perfectly, but that's not critical.

  • You really ask for that output: |- means "use the horizontal position of the first coordinate and the vertical position of the second". Just specify an absolute coordinate instead. – TeXnician Jul 3 '18 at 11:42
4

You can draw the lines as you like. The coordinates like and1.in 1 are just tikz coordinates on the nodes. By adding \usetikzlibrary{calc} to the preamble you can do coordinate manipulations. Sometimes it is easier to see what you are doing by adding coordinates. Below tmp is just and1.in 1 lifted 0.6cm. Then I draw first to the coordinate where tmp and orr1.out meet, and then back to x.

\coordinate (tmp) at ($(and1.in 1)+(0,0.6)$);
% \draw (tmp) circle (2pt);% Just to see where the coordinate is
\draw (and1.in 1) --(orr1.out |- tmp) -- (x |- tmp);
\draw[fill] (x |- tmp) circle (1pt);

It can also be done in one \draw

\draw (and1.in 1) -- ($(orr1.out |- and1.in 1) + (0,0.6)$) -- ($(x |- and1.in 1) + (0,0.6)$) node[fill,circle,inner sep=1pt]{};

enter image description here

I guess it was not the coloring you asked for, but here it is:-)

\draw[color=red!40!yellow!100,thick] (and1.in 1) -- ($(orr1.out |- and1.in 1) + (0,0.6)$) -- ($(x |- and1.in 1) + (0,0.6)$) node[fill,circle,inner sep=1pt]{};

enter image description here

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.