0

The following code

\documentclass[border=1pt]{standalone}

\usepackage{tikz} \usepackage{amsmath} \usepackage{xcolor} \usepackage{bm}

\usetikzlibrary{automata,positioning}

\begin{document} \begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] \node[state,accepting] (0) {$\bm{0}$}; \node[state,accepting] (3) [right=of 0] {$\bm{3}$}; \node[state,accepting] (6) [right=of 3] {$\bm{6}$}; \node[state] (1) [above=of 0] {$\bm{1}$}; \node[state] (2) [above=of 1] {$\bm{2}$}; \node[state] (4) [above=of 3] {$\bm{4}$}; \node[state] (5) [above=of 4] {$\bm{5}$}; \node[state] (7) [above=of 6] {$\bm{7}$}; \node[state] (8) [above=of 7] {$\bm{8}$};
\path[->] (0) edge [in=170, out=10] node {$v$} (3) (3) edge [in=170, out=10] node {$v$} (6) (6) edge [in=350, out=190] node {$w$} (3) (3) edge [in=350, out=190] node {$w$} (0) (6) edge [in=330, out=210] node [swap,yshift=-1mm] {$v$} (0) (0) edge [in=230, out=310] node [yshift=-1mm] {$w$} (6) (0) edge [in=280, out=80] node[swap,yshift=-2mm,xshift=-1mm] {$k$} (1) (3) edge [in=280, out=80] node[swap,yshift=-2mm,xshift=-1mm] {$k$} (4) (6) edge [in=280, out=80] node[swap,yshift=-2mm,xshift=-1mm] {$k$} (7) (7) edge [in=280, out=80] node[swap,yshift=-2mm,xshift=-1mm] {$k$} (8) (4) edge [in=280, out=80] node[swap,yshift=-2mm,xshift=-1mm] {$k$} (5) (1) edge [in=280, out=80] node[swap,yshift=-2mm,xshift=-1mm] {$k$} (2) (2) edge [in=100, out=260] node [swap,yshift=3mm,xshift=1mm] {$m$} (1) (5) edge [in=100, out=260] node[swap,yshift=3mm,xshift=1mm] {$m$} (4) (8) edge [in=100, out=260] node[swap,yshift=3mm,xshift=1mm] {$m$} (7) (1) edge [in=100, out=260] node[swap,yshift=3mm,xshift=1mm] {$e$} (0) (4) edge [in=100, out=260] node[swap,yshift=3mm,xshift=1mm] {$e$} (3) (7) edge [in=100, out=260] node[swap,yshift=3mm,xshift=1mm] {$e$} (6) (2) edge [in=125, out=330] node [yshift=14mm,xshift=-8.5mm] {$h$} (3) (1) edge [in=150, out=330] node [yshift=7mm,xshift=-6mm] {$h$} (3) (2) edge [in=125, out=330] node [yshift=14mm,xshift=-8.5mm] {$h$} (3) (5) edge [in=125, out=330] node [yshift=14mm,xshift=-8.5mm] {$h$} (6) (2) edge [in=125, out=330] node [yshift=14mm,xshift=-8.5mm] {$h$} (3) (4) edge [in=150, out=330] node [yshift=7mm,xshift=-6mm] {$h$} (6) (5) edge [in=55, out=220] node [yshift=19.5mm,xshift=4mm] {$l$} (0) (8) edge [in=55, out=220] node [yshift=19.5mm,xshift=4mm] {$l$} (3) (4) edge [in=30, out=210] node [yshift=12mm,xshift=3mm] {$l$} (0) (1) edge [in=30, out=210, color=blue] node [yshift=7mm,xshift=-28mm] {$l$} (6) (2) edge [in=20, out=210, color=blue] node [yshift=18mm,xshift=-28mm] {$l$} (6) (8) edge [in=120, out=150, color=red, looseness=1.9] node [yshift=4.5mm,xshift=38mm] {$h$} (0) (7) edge [in=135, out=60, color=red, looseness=3.5] node [yshift=-26mm,xshift=29mm] {$h$} (0);
\end{tikzpicture} \end{document}

Yields

enter image description here

with a lot of unwanted empty space around the state machine.

Why doesn't the option border=1pt of standalone work?

  • 3
    The curved lines add to the bounding box, because it will contain also the control points. – egreg Dec 14 '18 at 16:50
  • See https://tex.stackexchange.com/questions/290357/tikz-bounding-box-cropping-too-much-space-for-curves – egreg Dec 14 '18 at 16:51
  • I think it is related to @egreg comment; using xshift/yshift doesn't move the absolute coordinates of the nodes. So the bounding box include this absolute coordinates even though there is no visible thing there. – user1527152 Dec 14 '18 at 16:56

1 Answers1

1

this may help, if there is no other solution:

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
\useasboundingbox (-2,-1.5) rectangle (5,6);    

enter image description here