1

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

1 Answer 1

1

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

5
  • That's Great @dexteritas. Thank you very much! One another question is how I could use this among another article which I'm typing?
    – Aref
    Jul 27, 2017 at 13:03
  • 1
    If you leave this graphic in it's own file with documentclass standalone, you could import the resulting pdf into your article using the package graphicx and \includegraphics[width=\textwidth]{filename.pdf}
    – dexteritas
    Jul 27, 2017 at 13:09
  • Is it true if I type \documentclass[a4paper]{standalone}‎ I could get the result in the A4 paper format?
    – Aref
    Jul 28, 2017 at 8:08
  • I don't think so, but why don't you just try it?
    – dexteritas
    Jul 28, 2017 at 11:17
  • Another way would be to use article and then adjust the size of the graphic so that it is not too wide. There are answers to that question: Correctly scaling a tikzpicture or Force wide Tikz figure to move left.
    – dexteritas
    Jul 28, 2017 at 11:21

You must log in to answer this question.

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