我是 Tikz 的新手,曾尝试创建一个外观漂亮的主从 D 触发器,用于我的论文文档。良好的输出如下所示:
生成上图所用的代码是这样的:
\documentclass{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\usetikzlibrary{positioning, arrows, calc, circuits.logic.US}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
\renewcommand*{\familydefault}{\sfdefault}
\begin{document}
\tikzstyle{tg} = [rectangle, draw, text centered, text width=0.75em, minimum height=1em, thick, inner sep=0pt]
\tikzstyle{latch} = [rectangle, draw, text centered, text width=7.75em, minimum height=13em, thick, dashed, rounded corners, fill=gray!8]
\begin{tikzpicture}[scale=1, every node/.style={transform shape}, circuit logic US, huge circuit symbols]
\node [not gate, fill=gray!20, thick] (notd) {};
\node [latch] at (3.725,-1.5) (master) {};
\node [latch] at (7.825,-1.5) (slave) {};
\node [not gate,right=7em of notd.output, fill=gray!20, thick] (master1) {};
\node [not gate,below=8em of master1.center, rotate=180, fill=gray!20, thick] (master2) {};
\node [not gate,right=8em of master1.output, fill=gray!20, thick] (slave1) {};
\node [not gate,below=8em of slave1.center, rotate=180, fill=gray!20, thick] (slave2) {};
\node [not gate,right=3em of slave1.output, fill=gray!20, thick] (notq) {};
\node [tg, right=2em of notd] (tg1) {};
\node [above=0.05 of tg1.north west, inner sep=0pt] (tg1nw) {};
\node [above=0.05 of tg1.north east, inner sep=0pt] (tg1ne) {};
\node [below=0.05 of tg1.south west, inner sep=0pt] (tg1sw) {};
\node [below=0.05 of tg1.south east, inner sep=0pt] (tg1se) {};
\node [circle, above=0.18em of tg1.north, draw=black,thick,circle,inner sep=0pt, minimum size=0.25em] (tg1input) {};
\draw [thick] (tg1nw.center) -- (tg1ne.center);
\draw [thick] (tg1sw.center) -- (tg1se.center);
\node [tg, right=2.9em of master1.output] (tg2) {};
\node [above=0.05 of tg2.north west, inner sep=0pt] (tg2nw) {};
\node [above=0.05 of tg2.north east, inner sep=0pt] (tg2ne) {};
\node [below=0.05 of tg2.south west, inner sep=0pt] (tg2sw) {};
\node [below=0.05 of tg2.south east, inner sep=0pt] (tg2se) {};
\node [circle, below=0.18em of tg2.south, draw=black,thick,circle,inner sep=0pt, minimum size=0.25em] (tg2input) {};
\draw [thick] (tg2nw.center) -- (tg2ne.center);
\draw [thick] (tg2sw.center) -- (tg2se.center);
\node [left=1em of notd.input] (d) {D};
\draw [thick] (d) -- (notd.input);
\node [right=1em of notq.output] (q) {Q};
\draw [thick] (q) -- (notq.output);
\draw [thick] (notd.output) -- (tg1.west);
\draw [thick] (tg1.east) -- (master1.input);
\draw [thick] (master1.output) -- (tg2.west);
\draw [thick] (tg2.east) -- (slave1.input);
\draw [thick] (slave1.output) -- (notq.input);
\draw [thick] (master1.output) -- ++(0.5,0) |- (master2.input);
\draw [thick] (master2.output) -- ++(-0.5,0) |- (master1.input);
\draw [thick] (slave1.output) -- ++(0.5,0) |- (slave2.input);
\draw [thick] (slave2.output) -- ++(-0.5,0) |- (slave1.input);
\node [above=1em of tg1.north] (tg1in) {CLK};
\node [below=1em of tg1.south] (tg1inb) {$\overline{\mbox{CLK}}$};
\node [above=1em of tg2.north] (tg2in) {CLK};
\node [below=1em of tg2.south] (tg2inb) {$\overline{\mbox{CLK}}$};
\draw [thick] (tg1in) -- (tg1input.north);
\draw [thick] (tg1inb) -- ($(tg1se)!0.5!(tg1sw)$);
\draw [thick] (tg2in) -- ($(tg2ne)!0.5!(tg2nw)$);
\draw [thick] (tg2inb) -- (tg2input.south);
\node [circle, below=2em of master2.south, draw=black,thick,circle,inner sep=0pt, minimum size=0.5em] (mastercircle) {};
\node [circle, above=2em of slave2.north, draw=black,thick,circle,inner sep=0pt, minimum size=0.5em] (slavecircle) {};
\node [above=3em of master2.north] (clkm1) {CLK};
\node [below=3em of master2.south] (clkm2) {$\overline{\mbox{CLK}}$};
\draw [thick] (clkm1) -- (master2.south);
\draw [thick] (clkm2) -- (mastercircle.south);
\node [above=3em of slave2.north] (clks1) {CLK};
\node [below=3em of slave2.south] (clks2) {$\overline{\mbox{CLK}}$};
\draw [thick] (clks1) -- (slavecircle.north);
\draw [thick] (clks2) -- (slave2.north);
\node [above=0.1em of master.north] {Master};
\node [above=0.1em of slave.north] {Slave};
\end{tikzpicture}
\end{document}
但是,当我尝试将 Tikz 代码输入到我的论文文档中时,“主/从”框的坐标似乎不知何故发生了偏移。这是最明显的变化,但还有其他一些小的变化,例如锁存器中的反相器环以及传输门上的反相器环略有偏移。这是我的论文中的输出:
这可能是什么原因?我将其插入论文时没有进行任何缩放,应该是一样的。论文使用自定义文档类,我认为这可能会弄乱事情。在这种情况下,如何避免这种情况?
答案1
正如 Gonzalo Medina 在上面的评论中所说,错误在于我使用了埃姆定位块。我不知道这是一个与当前字体相关的大小选项,并且由于文档的字体不同,因此图形在每一页上的呈现方式都不同。
将值更改为绝对参数,例如毫米解决了问题。