[Tex/LaTex] Directed graphs with labels

graphstikz-pgf

I was trying to draw this graph but as you see two labels—x_1 and x_3—on the edges of 0110 and 1010 in the third row interfere. How can I fix it? And also do you have any opinion how I can write with a bigger and bald font in the circles and to insert the graph in the center of the page?

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\usepackage{verbatim}

\begin{document}

\begin{tikzpicture}[-triangle 60,auto,node distance=3.7cm,ultra thick]
\tikzstyle{every state}=[circle,thick,draw=blue!75,fill=blue!20,minimum 
 size=20mm,text=black,minimum width=1cm]

\node[state] (A)    {$0000$};
\node[state] (B) [below of=A] {$0100$}; 
\node[state] (C) [left of=B]  {$0010$};  
\node[state] (D) [right of=B] {$1000$};

\node[state] (E) [below of=B] {$1100$}; 
\node[state] (F) [left of=E]  {$0101$};
\node[state] (G) [left of=F]  {$0011$};
\node[state] (H) [right of=E] {$0110$};
\node[state] (I) [right of=H] {$1010$};

\node[state] (J) [below of=F] {$0111$};

\node[state] (K) [below of=H] {$0111$};

\path (B) edge      node {$x_2$} (A)          
      (C) edge      node {$x_3$} (A)            
      (D) edge      node {$x_1$} (A)

      (E) edge      node {$x_1$} (B)
          edge      node {$x_2$} (D)                       
      (F) edge      node {$x_4$} (B)        
      (G) edge      node {$x_4$} (C)                
      (H) edge      node {$x_2$} (C)
          edge      node {$x_3$} (B)                  
      (I) edge      node {$x_1$} (C)
          edge      node {$x_3$} (D)

      (J) edge      node {$x_2$} (G)
          edge      node {$x_3$} (F)
          edge      node {$x_4$} (H)

      (K) edge      node {$x_1$} (G)
          edge      node {$x_4$} (I);
      \end{tikzpicture}

      \end{document}

Best Answer

You can use the optional commands for node:

  • above, below, left, right: Position of the node
  • pos=x with x in [0,1]: Relative position of the node on the arrow
  • xshift=x, yshift=x where x is a distance: Shift on x or y axes

Here is the adapted code. I removed some unused imports and changed the documentclass to standalone.

\documentclass[margin=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}

\begin{document}

\begin{tikzpicture}[-triangle 60,auto,node distance=3.7cm,ultra thick]
    \tikzstyle{every state}=[circle,thick,draw=blue!75,fill=blue!20,minimum 
     size=20mm,text=black,minimum width=1cm]

    \node[state] (A)    {$0000$};
    \node[state] (B) [below of=A] {$0100$}; 
    \node[state] (C) [left of=B]  {$0010$};  
    \node[state] (D) [right of=B] {$1000$};

    \node[state] (E) [below of=B] {$1100$}; 
    \node[state] (F) [left of=E]  {$0101$};
    \node[state] (G) [left of=F]  {$0011$};
    \node[state] (H) [right of=E] {$0110$};
    \node[state] (I) [right of=H] {$1010$};

    \node[state] (J) [below of=F] {$0111$};

    \node[state] (K) [below of=H] {$0111$};

    \path (B) edge      node{$x_2$} (A)
          (C) edge      node{$x_3$} (A)
          (D) edge      node{$x_1$} (A)

          (E) edge      node[pos=0.3]{$x_1$} (B)
              edge      node[pos=0.7,above,xshift=-1mm]{$x_2$} (D)
          (F) edge      node{$x_4$} (B)
          (G) edge      node{$x_4$} (C)
          (H) edge      node[pos=0.1] {$x_2$} (C)
              edge      node[pos=0.7,above,xshift=1mm]{$x_3$} (B)
          (I) edge      node[pos=0.3,above]{$x_1$} (C)
              edge      node {$x_3$} (D)

          (J) edge      node{$x_2$} (G)
              edge      node{$x_3$} (F)
              edge      node{$x_4$} (H)

          (K) edge      node{$x_1$} (G)
              edge      node{$x_4$} (I);
\end{tikzpicture}

\end{document}

enter image description here

To change font size in tikz automata you can use:

\tikzset{every state/.append style={font=\Large}}