Friday, 23 August 2013

Tikz automaton placed too far to the right

Tikz automaton placed too far to the right

So I'm having a bit of trouble drawing an automaton that I've created.
I've been looking around for a while to no real avail, so I decided to
just ask the question myself: when I make an automaton (I'll post mine),
the entire diagram is too far to the right. Given the default spacing that
I had was 3.5cm, the diagram is perfectly visible throughout, nothing is
cut off, but when I wish to space the nodes out a little more, say, to
5.5cm, then half of my automaton falls off the right side of the screen
(ie it appears to never get drawn).
I've tried altering to starting position of the first node, under the
assumption that "every other node is just constructed around the first
one", but that didn't work. I tried using at (x, y), I've tried using
\centering, I've tried loads of things (half of which came from this very
site), but sadly, I cannot figure it out. Here is the code:
\documentclass[a4paper,10pt]{article}
%as of the 20th f August, 2013, all of the self-loops
%for all of the nodes are incomplete (ie if any
%nodes have self loops, the labels are not quite finished)
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata, positioning}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=5.5cm,
semithick]
\tikzstyle{every state}=[fill=red,draw=none,text=white]
\node[initial,state] (1) {$s_1$};
\node[state] (2) [below of=1] {$s_2$};
\node[state] (3) [above left of=1] {$s_3$};
\node[state] (4) [above right of=1] {$s_4$};
\node[state] (5) [below left of=3] {$s_5$};
\node[state] (6) [below right of=4] {$s_6$};
\node[state] (7) [below of=2] {$s_7$};
\node[state] (8) [below of=5] {$s_8$};
\node[state] (9) [below of=6] {$s_9$};
\path
(1) edge [bend left] node [sloped, below, pos=.3] {PG$\_$ON} (2)
edge [bend left] node [sloped, above] {CSP} (3)
edge [bend right] node [sloped, above] [swap, pos = .2] {CPSU} (4)
edge [loop above, looseness=30] node {PSUFull} (1)
(2) edge [bend left] node [sloped, above] {CSP} (5)
edge [bend right] node [sloped, above] {CPSU} (6)
edge node [swap, pos=.4, sloped, above] {PSUFull} (7)
edge [bend left] node [sloped, below, pos=.7] {PG$\_$OFF} (1)
edge [loop above] node {lowSP} (2)
(3) edge [bend left] node [sloped, below] {lowSP} (1)
edge [bend right] node [left, sloped, above] {PG$\_$ON} (5)
edge [loop above] node {CSP} (3)
(4) edge [bend right] node [sloped, above] {PG$\_$ON} (6)
edge [bend right] node [sloped, below] {PSU$\neg$Thresh} (1)
edge [loop above] node {CPSU} (4)
(5) edge [bend left] node [sloped, below] {lowSP} (2)
edge node [sloped, above] {PSUFull} (8)
edge [bend right] node [above, sloped] {PG$\_$OFF} (3)
edge [loop left, looseness=20] node {CSP} (5)
(6) edge [bend right] node [sloped, below] {PSU$\neg$Thresh} (2)
edge node [swap, sloped, above] {PSUFull} (9)
edge [bend right] node [sloped, below] {PG$\_$OFF} (4)
edge [loop right, looseness=20] node {CPSU} (6)
(7) edge [bend right] node [sloped, below] {CSP} (8)
edge [bend right] node [swap, sloped, above] {CPSU} (9)
edge [bend right] node [sloped, below] {PG$\_$OFF} (1)
edge [loop below] node {lowSP} (7)
(8) edge [bend right] node [sloped, swap] {lowSP} (7)
edge [bend left = 80] node [pos=.2, sloped, below] {PG$\_$OFF} (3)
edge [loop left] node {CSP} (8)
(9) edge [bend right] node [sloped, below] {PSU$\neg$Thresh} (7)
edge [bend right=80] node [swap, pos=.2] {PG$\_$OFF} (4)
edge [loop right] node {CPSU} (9);
\end{tikzpicture}
\end{document}
And the image:

I'm really sorry if this isn't formatted properly or if this question has
been asked before/is really foolish. I'm just stuck =/. Any help is
appreciated!

No comments:

Post a Comment