0

I'm a beginner at Tikz, and have tried to create a good looking master slave d-flip flop to be used in my thesis document. The good output looks like this: enter image description here

The code used to generate the picture above is this:

\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}

However, when I try to input the Tikz-code into my thesis document, the coordinates for the "master/slave"-boxes seem to become offset somehow. This is the most noticable change, but there are other small changes such as the inverter rings in the latches being slightly offset, as well as on the transmission gates. This is how the output looks like in my thesis: enter image description here

What could be the reason for this? I do not do any scaling when inserting it into my thesis, and it should be the same. The thesis uses a custom document class, which I am assuming could mess things up. In that case, how can this be avoided?

5
  • Your code doesn't compile: ! Package pgf Error: No shape named tg1se is known. Jul 12, 2013 at 1:21
  • You are using \node [latch] at ($(tg1se)!0.5!(tg1sw)$) (master) {}; before defining the node with name tg1se. Jul 12, 2013 at 1:25
  • Sorry about that, some errors snuck in. I've updated the code with an working example.
    – veor
    Jul 12, 2013 at 1:31
  • You are using relative lengths, as in below=8em of master1.center, so if your class changes the font size, the lengths will vary. Instead of em use an absolute unit cm, or mm, or pt. Jul 12, 2013 at 1:46
  • We recently had a similar discussion about this; tex.stackexchange.com/questions/122235/… . So ifyou have too many of those units you can enforce a font size for only the Tikz pictures.
    – percusse
    Jul 12, 2013 at 5:46

1 Answer 1

2

As Gonzalo Medina states in the comments above, the mistake was that I was using em to position the blocks. I did not knwo that this was a sizing option that is relative to the current font, and since the documents had different fonts the figures were rendered differently in each page.

Changing the values to an absolute parameter such as mm solved the problem.

You must log in to answer this question.

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