我在用 LaTeX 绘制带逻辑门的电路图时遇到了一些困难。我尝试过circuitikz
和pst-circ
。
\begin{pspicture}(-1,-1)(5,3)
\logicand[ninputs=2,invertinputa=true, invertinputb=true](0,0){Name}
\end{pspicture}
给出
Error: ! Undefined control sequence.
<recently read> \c@lor@to@ps
l.75 ...inputa=true, invertinputb=true](0,0){Name}
?
和
\begin{circuitikz} \draw
(0,2) node[and port] (myand1) {}
(0,0) node[and port] (myand2) {}
(2,1) node[xnor port] (myxnor) {};
(myand1.out) | (myxnor.in 1)
(myand2.out) | (myxnor.in 2)
\end{circuitikz}
不会产生错误,但逻辑门之间也不会出现线。
请帮助我从 LaTeX 代码生成逻辑图。(我需要 AND、OR、NOT、NOR 和 NAND 门。)
答案1
对于circuitikz
方法:您需要告诉 TikZ 如何处理(myand1.out)
、(myxnor.in 1)
等。目前,您只提到节点,但不要告诉 TikZ 实际连接它们,因为您\draw
已经用 结束了上一个命令;
。此外,要用直线连接节点,您需要使用--
,而不是|
。
这是完整 MWE 中的示例。
\documentclass{article}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz} \draw
(0,2) node[and port] (myand1) {}
(0,0) node[and port] (myand2) {}
(2,1) node[xnor port] (myxnor) {}
(myand1.out) -- (myxnor.in 1)
(myand2.out) -- (myxnor.in 2);
\end{circuitikz}
\end{document}
答案2
我从未使用过circuitikz
tikzlibrary shapes.gates.logic
。您有 AND、NOT、NOR 和所有逻辑门,将它们放置为常规 tikz 节点并绘制连接。就这样。这里有一个例子:
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes.gates.logic.US,shapes.gates.logic.IEC,calc}
\begin{document}
\thispagestyle{empty}
\tikzstyle{branch}=[fill,shape=circle,minimum size=3pt,inner sep=0pt]
\begin{tikzpicture}[label distance=2mm]
\node (x3) at (0,0) {$x_3$};
\node (x2) at (1,0) {$x_2$};
\node (x1) at (2,0) {$x_1$};
\node (x0) at (3,0) {$x_0$};
\node[not gate US, draw, rotate=-90] at ($(x2)+(0.5,-1)$) (Not2) {};
\node[not gate US, draw, rotate=-90] at ($(x1)+(0.5,-1)$) (Not1) {};
\node[not gate US, draw, rotate=-90] at ($(x0)+(0.5,-1)$) (Not0) {};
\node[or gate US, draw, logic gate inputs=nnn] at ($(x0)+(2,-2)$) (Or1) {};
\node[or gate US, draw, logic gate inputs=nnnn] at ($(Or1)+(0,-1)$) (Or2) {};
\node[or gate US, draw, logic gate inputs=nnn] at ($(Or2)+(0,-1)$) (Or3) {};
\node[xor gate US, draw, logic gate inputs=nn] at ($(Or3)+(0,-1)$) (Xor1) {};
\node[and gate US, draw, logic gate inputs=nn, anchor=input 1] at ($(Or3.output)+(1,0)$) (And1) {};
\node[nor gate US, draw, logic gate inputs=nn, anchor=input 1] at ($(Or2.output -| And1.output)+(1,0)$) (Nor1) {};
\node[and gate US, draw, logic gate inputs=nn, anchor=input 1] at ($(Or1.output -| Nor1.output)+(1,0)$) (And2) {};
\foreach \i in {2,1,0}
{
\path (x\i) -- coordinate (punt\i) (x\i |- Not\i.input);
\draw (punt\i) node[branch] {} -| (Not\i.input);
}
\draw (x3) |- (Or2.input 1);
\draw (x3 |- Or1.input 1) node[branch] {} -- (Or1.input 1);
\draw (x2) |- (Xor1.input 1);
\draw (x2 |- Or3.input 1) node[branch] {} -- (Or3.input 1);
\draw (Not2.output) |- (Or2.input 2);
\draw (x1) |- (Or3.input 2);
\draw (x1 |- Or1.input 2) node[branch] {} -- (Or1.input 2);
\draw (Not1.output) |- (Xor1.input 2);
\draw (Not1.output |- Or2.input 3) node[branch] {} -- (Or2.input 3);
\draw (x0) |- (Or2.input 4);
\draw (Not0.output) |- (Or3.input 3);
\draw (Not0.output |- Or1.input 3) node[branch] {} -- (Or1.input 3);
\draw (Or3.output) -- (And1.input 1);
\draw (Xor1.output) -- ([xshift=0.5cm]Xor1.output) |- (And1.input 2);
\draw (Or2.output) -- (Nor1.input 1);
\draw (And1.output) -- ([xshift=0.5cm]And1.output) |- (Nor1.input 2);
\draw (Or1.output) -- (And2.input 1);
\draw (Nor1.output) -- ([xshift=0.5cm]Nor1.output) |- (And2.input 2);
\draw (And2.output) -- ([xshift=0.5cm]And2.output) node[above] {$f_1$};
\end{tikzpicture}
\end{document}
答案3
我不完全确定你想要什么;这里有一个直接从文档中获取的示例,你可以通过运行找到它
texdoc pst-circ
使用时PSTricks
如果你使用
latex myfile.tex
dvips myfile.dvi
ps2pdf myfile.ps
那么以下文件将起作用
\documentclass{article}
\usepackage{pst-circ}
\begin{document}
\begin{pspicture}(-4,0)(5,7)
\psset{logicWidth=1, logicHeight=2, dotsize=0.15}
\logic[logicWireLength=0](-2,0){A0}
\logic[logicWireLength=0](-2,5){A1}
\ncbar[angleA=-180,angleB=-180,arm=0.5]{A11}{A02}
\psline[dotsize=0.15]{-*}(-3.5,3.5)(-2.5,3.5)
\uput[180](-3.5,3.5){$T$}
\psline(-3.5,0.5)(A01)\uput[180](-3.5,0.5){$S$}
\psline(-3.5,6.5)(A12)\uput[180](-3.5,6.5){$R$}
\psset{logicType=nor, logicLabelstyle=\normalsize}
\logic(1,0.5){nor1}
\logic(1,4.5){nor2}
\psline(nor2Q)(4,0|nor2Q)
\uput[0](4,0|nor2Q){$Q$}
\psline(nor1Q)(4,0|nor1Q)
\uput[0](4,0|nor1Q){$\overline{Q}$}
\psline{*-}(3,0|nor2Q)(3,4)(1,4)(0,3)(0,0|nor12)(nor12)
\psline{*-}(3,0|nor1Q)(3,3)(1,3)(0,4)(0,0|nor21)(nor21)
\psline(A0Q)(nor11)
\psline(A1Q)(nor22)
\end{pspicture}
\end{document}
如果你更喜欢使用,pdflatex
那么你的序言应该是这样的
\documentclass{article}
\usepackage[pdf]{pstricks}
\usepackage{pst-circ}
\begin{document}
...
然后你可以运行
pdflatex -shell-escape myfile.tex
答案4
尝试这个发电机适用于简单情况并且使用 Tikz
对于你的情况,乳胶代码将是这样的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\begin{document}
\usetikzlibrary {circuits.logic.US}
\begin{tikzpicture}[circuit logic US]
\matrix[column sep=4mm, row sep=4mm] {
\node [and gate ] (f5fbb9ac-ba33-4ab5-96bc-d0af34cee8a1) {}; & & \\
& & \node [xnor gate ] (a6b7442d-0f66-4798-9db4-25a81365166e) {}; \\
\node [and gate ] (ca150480-f272-4220-9df1-14d5893b1ae2) {}; & & \\
};
\draw (f5fbb9ac-ba33-4ab5-96bc-d0af34cee8a1.output) -- ++(right:2mm) |- (a6b7442d-0f66-4798-9db4-25a81365166e.input 1);
\draw (ca150480-f272-4220-9df1-14d5893b1ae2.output) -- ++(right:2mm) |- (a6b7442d-0f66-4798-9db4-25a81365166e.input 2);
\end{tikzpicture}
\end{document}