我正在尝试绘制一种针对两个四位输入的相等性测试电路的简单方法。我是否可以强制将线路完全垂直和横向连接,并在必要时以直角连接这些点,而不是以斜角连接门输入和输出的两个点。我需要在保持标记线路的能力的同时做到这一点,如图所示。当我第一次制作图表时,线路就像我希望的那样,用“-|”参数或运算符代替“to”,但我找不到用该方法实例化线路以接受标签的方法。非常感谢您的帮助和考虑。
\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}
答案1
您可以通过添加节点在线上放置标签。请参阅第 17.8 节(明确地在线或曲线上放置节点)pgf/tikz 手册。
\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}
在这个例子中我使用了midway
,但还有其他键可以微调标签的位置。
答案2
您可以使用和\draw
来画线。|-
-|
以下是示例的摘录:
\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}