增加 tikzpicture 中节点之间的间距

增加 tikzpicture 中节点之间的间距

在此处输入图片描述

如何增加节点 A 和 B 之间的间距?目前它们彼此相邻。另外,有没有办法防止节点 H 与其他节点重叠?

上述输出是由以下命令产生的。

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,quotes, positioning}
\tikzset{block/.style={ellipse, draw, fill=gray!20, 
    text width=8em, text centered, rounded corners, minimum height=4em, width=4em},
    line/.style={draw, -latex'},}
\begin{document}


\begin{tikzpicture}[node distance = 3cm, auto]
     \node [block] (A) {A};
\node [block,right of=A] (B) {B};
\node [block, above of=A] (C) {C};
\node [block, above of=B] (D) {D};
\node [block, below left of=B, below right of=A] (E) {E};
\node [block, right of=E] (F) {F};
\node [block, above right of=F, node distance=3cm] (G) {G};
\node [block, above of=G] (H) {H};

% Draw edges
\path [line] (C) edge["a"'] (A) ;
\path [line] (D) edge["b"']  (B) ;
\path [line] (A) -- (E);
\path [line] (B) -- (E);
\path [line] (F) --  (E);
\path [line] (F) edge["g"'] (G) ;
\path [line] (G) edge["h"']  (H);

\end{tikzpicture}
\end{document}

编辑:根据 Skillmon 的回答编辑以包含环境。抱歉最初没有让我的代码可编译

答案1

我为您的代码添加了一个最小环境,以便我可以对其进行处理。您不应使用语法,right of=A而应使用right=of A。我还添加了一个between键来放置 E,请注意,这below right=of A, below left=of B只会导致below left=of B前者被忽略。此外,ysepxsep键似乎在当前 Ti 中不存在Z 版本(我的是 3.0.1a)。

\documentclass[tikz]{standalone}

\usetikzlibrary{arrows,quotes,positioning,shapes,calc}

\tikzset
  {
    block/.style=%
      {%
        ellipse, draw, fill=gray!20, text width=8em, text centered, rounded
        corners, minimum height=4em, minimum width=4em
      }
    ,line/.style={draw, -latex'}
    % https://tex.stackexchange.com/a/138828/117050
    ,between/.style args={#1 and #2}{at=($(#1)!0.5!(#2)$)}
  }

\begin{document}
\begin{tikzpicture}[node distance = 2cm, auto]
  \node [block] (A) {A};
  \node [block,right=of A] (B) {B};
  \node [block, above=of A] (C) {C};
  \node [block, above=of B] (D) {D};
  \node [block, between=A and B, yshift=-2.5cm] (E) {E};
  \node [block, right=of E] (F) {F};
  \node [block, right=of B] (G) {G};
  \node [block, right=of D] (H) {H};

  % Draw edges
  \path [line] (C) edge["a"'] (A) ;
  \path [line] (D) edge["b"']  (B) ;
  \path [line] (A) -- (E);
  \path [line] (B) -- (E);
  \path [line] (F) --  (E);
  \path [line] (F) edge["g"'] (G) ;
  \path [line] (G) edge["h"']  (H);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容