1

enter image description here

How can I increase the spacing between nodes A and B? Right now they are right beside each other. Also, is there a way to prevent node H from overlapping with the other nodes?

The above output is produced from the following commands.

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

Edit: edited to include environment based on Skillmon's answer. Apologies for not making my code compilable initially

  • 1
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Skillmon Nov 19 '18 at 09:23
  • Note that you need to load the shapes library to get ellipse to work. – Skillmon Nov 19 '18 at 10:13

1 Answers1

3

I added a minimal environment to your code so that I can work on it. You shouldn't use the right of=A syntax but instead use right=of A. I've also added a between key to place E, note that below right=of A, below left=of B will just result in below left=of B the former being ignored. Also the ysep and xsep keys seem to not exist in current TikZ versions (mine is 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}

enter image description here

Skillmon
  • 60,462