Tikz 自动机放置得太靠右

Tikz 自动机放置得太靠右

所以我在绘制我创建的自动机时遇到了一些麻烦。我找了好一阵子,但一无所获,所以我决定自己问这个问题:当我制作一个自动机(我会发布我的自动机)时,整个图表都太靠右了。考虑到我的默认间距是 3.5 厘米,整个图表都清晰可见,没有任何东西被切断,但是当我希望将节点间距再拉大一点,比如说 5.5 厘米时,我的自动机的一半就会从屏幕右侧掉下来(即它似乎永远不会被绘制出来)。

我曾尝试改变第一个节点的起始位置,假设“其他每个节点都是围绕第一个节点构建的”,但那没有用。我试过使用at (x, y),我试过使用\centering,我试过很多东西(其中一半来自这个网站),但遗憾的是,我无法弄清楚。以下是代码:

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

图片如下:

我的自动机失败了

如果格式不正确或者这个问题之前有人问过/真的很愚蠢,我真的很抱歉。我只是被困住了=/。任何帮助都非常感谢!

答案1

您有以下几种选择:

增加纸张尺寸:

可能不是一个可行的选择,但是为了完成:请参阅LaTeX 维基百科以获取详尽列表。

降低边距:

\usepackage[margin=1pt]{geometry}

在这种情况下,根本就没有足够的空间。

使用standalone类:

将图像外部化到不同的文件中。

\documentclass[tikz]{standalone}

\usetikzlibrary{arrows,automata, positioning}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[...]
...

这样可以将所有内容放在一页上,并可轻松将其包含在主文档中,\includegraphics[width=\textwidth]{mytikzautomaton} 这也可以加快主文档的编译速度相当

在此处输入图片描述

缩放整个绘图:

这需要相当多的调整才能看起来不错,并且不是一个非常强大的解决方案,但需要最少的努力。

\begin{tikzpicture}[..., scale=0.9,
      every node/.style={scale=0.9}]
...

完整示例使用standalone

\documentclass[tikz]{standalone}

\usetikzlibrary{arrows,automata, positioning}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=5.5cm,
                semithick,
                scale=0.9, every node/.style={scale=0.9}]
    \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}

相关内容