2

for example, I have the wires that run from the node b_2 which I want it to split to both label_g2 and XOR1.in 1, currently, I have 2 things I don't like about it:

  1. I have to do it with two different \draw functions and it looks like there's overlap in the first segment (rendering that part thicker)
  2. the wire split is too far, I want to make it halfway between b_2 and the x position of XOR1.in 1 (without using exact coordinates)
  3. I want to know if there's a way to automatically adjust nodes in relation to other nodes, for example here I've set the location of the g1,g0 nodes by hand, but I would have liked to have some way to make a straight line from the logic gate output (or whatever node) directly to g1/g0 generally.
\begin{document}

\begin{circuitikz} 

\node[anchor=base] (label_b2) at (-2,1.5) {$b_2$}; 
\node[anchor=base] (label_b1) at (-2,0) {$b_1$}; 
\node[anchor=base] (label_b0) at (-2,-1.5) {$b_0$}; 

\node[anchor=base] (label_g2) at (3,1.5) {$g_2$}; 
\node[anchor=base] (label_g1) at (3,0.26) {$g_1$}; 
\node[anchor=base] (label_g0) at (3,-1.24) {$g_0$}; 

\node[ieeestd xor port, scale=0.75] (XOR1) at (0.5,0.3) {};
\draw (label_b2) -|node[circ]{} (XOR1.in 1) node[anchor=east] {\scriptsize $b_2$};   
\draw (label_b1) -- (XOR1.in 2) node[below] {\scriptsize $b_1$}; 
\draw (XOR1.out) |-node{} (label_g1) ; 
\draw (label_b2) -- (label_g2) ; 

\node[ieeestd xor port, scale=0.75] (XOR2) at (0.5,-1.2) {};
\draw (label_b1) -|node[circ]{} (XOR2.in 1) node[anchor=east] {\scriptsize $b_1$};   
\draw (label_b0) -- (XOR2.in 2) node[below] {\scriptsize $b_0$}; 
\draw (XOR2.out) |-node{} (label_g0) ; 


\end{circuitikz}

\end{document}

this is the rendered output:

enter image description here

0

1 Answer 1

2

There are various issues here. If you look closely, the line from b₂ to g₂ is not horizontal --- the two nodes have different sizes and different base anchors, so when you draw the line to the node as opposed to the anchor, you get the border anchor nearest which is not correct. Moreover, the other connections are horizontal just by guessing coordinates...

I would do the following.

You want IEEE standard ports with 0.75 scale. State it in the preamble, that will assure consistency.

\ctikzset{logic ports=ieee, logic ports/scale=0.75}

Start with the top line (you can go the other way around, this is just my choice)

\path (-2,1.5) coordinate(label_b2) node[anchor=base east]{$b_2$};
\path (3,1.5) coordinate(label_g2) node[anchor=base west]{$g_2$};

to be sure to have the coordinates at the right point.

Then you place the first port, and if you want the label b₁ exactly 1.5 units below b₂, you can put the port using the anchor in 2 at a point with y coordinate 0 and connect it:

\node[xor port, anchor=in 2] (XOR1) at (0,0) {};
\draw (label_b2) -| node[circ](up dot){} (XOR1.in 1)
    node[anchor=east] {\scriptsize $b_2$};
\draw (up dot) -- (label_g2);

And now you have this:

enter image description here

if you want the vertical line to be more to the left, you can do it manually like this:

\node[xor port, anchor=in 2] (XOR1) at (0,0) {};
\draw (label_b2) --++(1,0) node[circ](up dot){} |- (XOR1.in 1) 
    node[above left] {\scriptsize $b_2$};
\draw (up dot) -- (label_g2);

enter image description here

...and the two labels b₁ and g₁:

\draw (XOR1.in 2) -- (XOR1.in 2 -| label_b2) node[anchor=base east]{$b_1$};
\draw (XOR1.out)  -- (XOR1.out -| label_g2) node[anchor=base west]{$g_1$};

enter image description here

The rest is similar. The complete MWE, without any magic number or strange coordinates, is:

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[siunitx, RPvoltages]{circuitikz}
\ctikzset{logic ports=ieee, logic ports/scale=0.75}
\tikzset{input text/.style={font=\scriptsize,
    above left, inner sep=2pt}}

\begin{document}
\begin{circuitikz}
    \path (-2,1.5) coordinate(label_b2) node[anchor=base east]{$b_2$};
    \path (3,1.5) coordinate(label_g2) node[anchor=base west]{$g_2$};

    \node[xor port, anchor=in 2] (XOR1) at (0,0) {};
    \draw (label_b2) --++(1,0) node[circ](up dot){} |- (XOR1.in 1)
        node[input text] {$b_2$};
    \draw (up dot) -- (label_g2);
    \draw (XOR1.in 2) node[input text] {$b_1$} -- (XOR1.in 2 -| label_b2)
        coordinate(label_b1) node[anchor=base east]{$b_1$};
    \draw (XOR1.out)  -- (XOR1.out -| label_g2) coordinate(label_g1)
        node[anchor=base west]{$g_1$};

    \node[xor port, anchor=in 2] (XOR2) at (0,-1.5) {};
    %% we do not over-draw here: start from the dot!
    \draw (label_b1-|up dot) node[circ](mid dot){} |- (XOR2.in 1)
        node[input text] {$b_1$};
    \draw (XOR2.in 2) node[input text]{$b_0$} -- (XOR2.in 2 -| label_b1)
        node[anchor=base east]{$b_0$};
    \draw (XOR2.out)  -- (XOR2.out -| label_g1) node[anchor=base west]{$g_0$};
\end{circuitikz}
\end{document}

enter image description here

I prefer to use simply east, west instead of base anchors for the lateral labels, but that's a matter of taste...

4
  • can you explain to me why you chose fo b_2 and g_2 to draw them with a \path and the rest with \draw commands? are there some hidden properties in \path? or some other reason?
    – Nate3384
    Commented Jun 20 at 16:33
  • \draw is just a shortcut for \path[draw]. I normally use path when I don't want to draw any line, just place nodes and define coordinates. But there is no practical difference in this case, so it's just a matter of personal preferences...
    – Rmano
    Commented Jun 20 at 17:37
  • where can i better learn how to deal with wiring and connections in tikz? is this in the circuitikz manual or a different manual? how have you achieved such a mastery of it?
    – Nate3384
    Commented Jun 21 at 13:40
  • This is basically basic TikZ - look at least at the first tutorial in the manual and then coordinate systems and node positioning: tikz.dev
    – Rmano
    Commented Jun 21 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .