Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have been using the Tikz package to draw NFA's and DFA's, and it's a good package to do so with, but sometimes I have to be extra creative in my setup of it. It would be much easier if there was a possibility to make change one distance between two nodes. Does anybody know if such a possibility exists with the Tikz package?

\documentclass[a4paper,12pt]{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}

\begin{document}

\begin{figure}
\begin{tikzpicture}[node distance = 2cm]

\node[initial,state]        (1)                     {$1$};
\node[state]                (2) [right of=1]        {$2$};
\node[accepting,state]      (3) [right of=2]        {$3$};

\path (1) edge    node  {}  (2)
      (2) edge    node  {}  (3);
%ex make the distance between node 2 and 3 more than 2 cm

\end{tikzpicture}
\end{figure}

\end{document}
share|improve this question

2 Answers 2

up vote 7 down vote accepted

You can also use positioning library:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,positioning}

\begin{document}

\begin{figure}
\begin{tikzpicture}[node distance = 2cm]

\node[initial,state]        (1)                     {$1$};
\node[state]                (2) [right of=1]        {$2$};
\node[accepting,state]      (3) [right =4cm of 2,blue,ultra thick]        {$3$};

\path (1) edge    node  {}  (2)
      (2) edge    node  {}  (3);
%ex make the distance between node 2 and 3 more than 2 cm

\end{tikzpicture}
\end{figure}

\end{document}
share|improve this answer
    
Not sure why I keep forgetting about that. Nice choice of coloring though. :-) –  Peter Grill Dec 6 '12 at 1:38

You can move a node by adding xshift=<length>:

enter image description here

Using node distance=4cm also seems to work.

Code:

\documentclass[a4paper,12pt]{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}

\begin{document}

\begin{figure}
\begin{tikzpicture}[node distance = 2cm]

\node[initial,state]        (1)                     {$1$};
\node[state]                (2) [right of=1]        {$2$};
\node[accepting,state]      (3) [right of=2,xshift=2cm,blue,ultra thick]        {$3$};

\path (1) edge    node  {}  (2)
      (2) edge    node  {}  (3);
%ex make the distance between node 2 and 3 more than 2 cm

\end{tikzpicture}
\end{figure}

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.