7

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}

2 Answers 2

10

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}
1
  • Not sure why I keep forgetting about that. Nice choice of coloring though. :-) Commented Dec 6, 2012 at 1:38
10

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}

You must log in to answer this question.

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