5

I am attempting to diagram a simple approach to an equality testing circuit for two four-bit inputs. Circuit Diagram generated from the following code Instead of the wires being at an oblique angle to connect the two points of gate inputs and outputs, can I force the lines to be purely vertical and lateral with right angles as necessary to connect the points. I need to do this while maintaining the ability to label the wires as shown. When I first made the diagram, the wires were as I had hoped with the '-|' argument or operator in place of 'to', but I could not find a way to get wires instantiated with that method to accept labels. Thank you very much for your assistance and consideration.

\documentclass[12pt,letterpaper]{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} \draw
    (0,0) node[xor port] (g7) {$g_7$}
    (0,2) node[xor port] (g6) {$g_6$}
    (0,4) node[xor port] (g5) {$g_5$}
    (0,6) node[xor port] (g4) {$g_4$}
    (3,1) node[or port] (g3) {$g_3$}
    (3,5) node[or port] (g2) {$g_2$}
    (6,3) node[or port] (g1) {$g_1$}
    (g4.out) to [short,l=${w_4}$] (g2.in 1)
    (g5.out) to [short,l=${w_5}$] (g2.in 2)
    (g6.out) to [short,l=${w_6}$] (g3.in 1)
    (g7.out) to [short,l=${w_7}$] (g3.in 2)
    (g2.out) to [short,l=${w_2}$] (g1.in 1)
    (g3.out) to [short,l=${w_3}$] (g1.in 2)
    (g1.out) node[anchor=west] {$output$}
    (g4.in 1) node[anchor=east] {$a_3$}
    (g4.in 2) node[anchor=east] {$b_3$}
    (g5.in 1) node[anchor=east] {$a_2$}
    (g5.in 2) node[anchor=east] {$b_2$}
    (g6.in 1) node[anchor=east] {$a_1$}
    (g6.in 2) node[anchor=east] {$b_1$}
    (g7.in 1) node[anchor=east] {$a_0$}
    (g7.in 2) node[anchor=east] {$b_0$}

;\end{circuitikz}
\end{document}
5

You can place a label on a line by adding a node. See section 17.8 (Placing Nodes on a Line or Curve Explicitly) of the pgf/tikz manual.

\documentclass[12pt,letterpaper]{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} \draw
    (0,0) node[xor port] (g7) {$g_7$}
    (0,2) node[xor port] (g6) {$g_6$}
    (0,4) node[xor port] (g5) {$g_5$}
    (0,6) node[xor port] (g4) {$g_4$}
    (3,1) node[or port] (g3) {$g_3$}
    (3,5) node[or port] (g2) {$g_2$}
    (6,3) node[or port] (g1) {$g_1$}
    (g4.out) -| (g2.in 1) node[midway, above] {$w_4$}
    (g5.out) -| (g2.in 2) node[midway, below] {$w_5$}
    (g6.out) -| (g3.in 1) node[midway, above] {$w_6$}
    (g7.out) -| (g3.in 2) node[midway, below] {$w_7$}
    (g2.out) -| (g1.in 1) node[midway, above] {$w_2$}
    (g3.out) -| (g1.in 2) node[midway, below] {$w_3$}
    (g1.out) node[anchor=west] {$output$}
    (g4.in 1) node[anchor=east] {$a_3$}
    (g4.in 2) node[anchor=east] {$b_3$}
    (g5.in 1) node[anchor=east] {$a_2$}
    (g5.in 2) node[anchor=east] {$b_2$}
    (g6.in 1) node[anchor=east] {$a_1$}
    (g6.in 2) node[anchor=east] {$b_1$}
    (g7.in 1) node[anchor=east] {$a_0$}
    (g7.in 2) node[anchor=east] {$b_0$}

;\end{circuitikz}
\end{document}

In this example I used midway, but there are other keys to fine tune the position of the label.

  • I didn't consider adding a node, though now that you demonstrated it, that seems intuitive. Thank you for citing the documentation concerning it too. – Ken Goss Jul 4 '17 at 16:13
6

You can \draw lines with |- and -|.

Here is an extract of your example:

\documentclass[12pt,letterpaper]{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} \draw
    (0,4) node[xor port] (g5) {$g_5$}
    (0,6) node[xor port] (g4) {$g_4$}
    (3,5) node[or port] (g2) {$g_2$}
    (g4.in 1) node[anchor=east] {$a_3$}
    (g4.in 2) node[anchor=east] {$b_3$}
    (g5.in 1) node[anchor=east] {$a_2$}
    (g5.in 2) node[anchor=east] {$b_2$}

    (g4.out) |- node[above right]{${w_4}$} (g2.in 1)
    (g5.out) |- node[below right]{${w_3}$} (g2.in 2)
    ;
\end{circuitikz}
\end{document}

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.