节点之间的个体路径距离

节点之间的个体路径距离

我一直在使用 Tikz 包来绘制 NFA 和 DFA,这是一个很好的包,但有时我必须在设置时发挥额外的创造力。如果有可能改变两个节点之间的距离,那就容易多了。有人知道 Tikz 包是否存在这种可能性吗?

\documentclass[a4paper,12pt]{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}

\begin{document}

\begin{figure}
\begin{tikzpicture}[node distance = 2cm]

\node[initial,state]        (1)                     {$1$};
\node[state]                (2) [right of=1]        {$2$};
\node[accepting,state]      (3) [right of=2]        {$3$};

\path (1) edge    node  {}  (2)
      (2) edge    node  {}  (3);
%ex make the distance between node 2 and 3 more than 2 cm

\end{tikzpicture}
\end{figure}

\end{document}

答案1

您还可以使用positioning库:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,positioning}

\begin{document}

\begin{figure}
\begin{tikzpicture}[node distance = 2cm]

\node[initial,state]        (1)                     {$1$};
\node[state]                (2) [right of=1]        {$2$};
\node[accepting,state]      (3) [right =4cm of 2,blue,ultra thick]        {$3$};

\path (1) edge    node  {}  (2)
      (2) edge    node  {}  (3);
%ex make the distance between node 2 and 3 more than 2 cm

\end{tikzpicture}
\end{figure}

\end{document}

答案2

您可以通过添加以下内容来移动节点xshift=<length>

在此处输入图片描述

使用node distance=4cm似乎也有效。

代码:

\documentclass[a4paper,12pt]{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}

\begin{document}

\begin{figure}
\begin{tikzpicture}[node distance = 2cm]

\node[initial,state]        (1)                     {$1$};
\node[state]                (2) [right of=1]        {$2$};
\node[accepting,state]      (3) [right of=2,xshift=2cm,blue,ultra thick]        {$3$};

\path (1) edge    node  {}  (2)
      (2) edge    node  {}  (3);
%ex make the distance between node 2 and 3 more than 2 cm

\end{tikzpicture}
\end{figure}

\end{document}

相关内容