[Tex/LaTex] Position of nodes in TIKZ

graphspositioningtikz-arrowstikz-pgftikz-styles

I have the following code:

\documentclass[a4paper, 11pt]{article}
\usepackage{comment} % enables the use of multi-line comments (\ifx \fi) 
\usepackage{fullpage} % changes the margin
\usepackage[swedish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{titlesec}
\usepackage{pgf, tikz}
\usetikzlibrary{arrows, automata}
\usepackage{color}


 \begin{document}
\begin{tikzpicture}[
        > = stealth, % arrow head style
        shorten > = 1pt, % don't touch arrow head to node
        auto,
        node distance = 2cm, % distance between nodes
        semithick % line style
    ]

    \tikzstyle{every state}=[
        draw = black,
        thin,
        fill = cyan!29,
        minimum size = 5mm
    ]

    \node[state] (a) {$a$};
    \node[state] (b)[below left=0.2cm and 0.2cm of a] {$b$};
    \node[state] (c)[below left=0.2cm and 0.2cm of b] {$c$};
    \node[state] (f)[below left=0.2cm and 0.2cm of c] {$f$};
    \node[state] (j)[below left=0.2cm and 0.2cm of f ] {$j$};
    \node[state] (d)[below left=0.2cm and 0.2cm of j] {$d$};
    \node[state] (i)[below left=0.2cm and 0.2cm of d] {$i$};

     \path[->] (a) edge node {} (b);
      \path[->] (b) edge node {} (c);
       \path[->] (c) edge node {} (f);
        \path[->] (f) edge node {} (j);
         \path[->] (j) edge node {} (d);
          \path[->] (d) edge node {} (i);
          \path[->] (b) edge[bend right=45, blue, very thick] node {} (j);


   \end{tikzpicture}
\end{document}

I would like the nodes to be more under each other, not so spread on the left. How can I achieve such a positioning? Thanks.

Best Answer

You can adjust the parameters to your node distance, to e.g.

node distance=1cm and 0cm

The first is vertical offset, the second horizontal. Note that with below left you are attaching to a "lower left" corner of the node and even the and 0cm will give a displacement to the left. You can make this number negative, but if you want a vertical stack then you should just use below instead of below left:

Sample output

\documentclass[a4paper, 11pt]{article}

\usepackage{tikz}
\usetikzlibrary{positioning, arrows, automata}

\begin{document}

\begin{tikzpicture}[ > = stealth, % arrow head style
        shorten > = 1pt, % don't touch arrow head to node
        semithick % line style
    ]

    \tikzstyle{every state}=[
        draw = black,
        thin,
        fill = cyan!29,
        minimum size = 7mm
    ]
    \begin{scope}[node distance=1cm and 0cm, every node/.style=state]
      \node (a) {$a$};
      \node (b) [below left=of a] {$b$};
      \node (c) [below left=of b] {$c$};
      \node (f) [below left=of c] {$f$};
      \node (j) [below left=of f] {$j$};
      \node (d) [below left=of j] {$d$};
      \node (i) [below left=of d] {$i$};
    \end{scope}
    \path[->] (a) edge (b)
              (b) edge (c)
              (c) edge (f)
              (f) edge (j)
              (j) edge (d)
              (d) edge (i)
              (b) edge[bend right=45, blue, very thick] (j);
\end{tikzpicture}
\hspace{2cm}
\begin{tikzpicture}[ > = stealth, % arrow head style
        shorten > = 1pt, % don't touch arrow head to node
        semithick % line style
    ]

    \tikzstyle{every state}=[
        draw = black,
        thin,
        fill = cyan!29,
        minimum size = 7mm
    ]
    \begin{scope}[node distance=1cm, every node/.style=state]
      \node (a) {$a$};
      \node (b) [below=of a] {$b$};
      \node (c) [below=of b] {$c$};
      \node (f) [below=of c] {$f$};
      \node (j) [below=of f] {$j$};
      \node (d) [below=of j] {$d$};
      \node (i) [below=of d] {$i$};
    \end{scope}
    \path[->] (a) edge (b)
              (b) edge (c)
              (c) edge (f)
              (f) edge (j)
              (j) edge (d)
              (d) edge (i)
              (b) edge[bend right=45, blue, very thick] (j);
\end{tikzpicture}

\end{document}