Automatically center labels between Tikz nodes

I am new to using Tikz latex package and I am trying to write a table. My problem is to create enough space between the siblings so that I can place the shortcut in the center. This is what I did. I would like to avoid the manual distance as much as possible, so I am looking for a general solution.

 \begin{tikzpicture}[auto, node distance=1.3cm]


 \node (A) {$X^1$};
 \node (B) [below of=A] {$X^2$};
 \node (C) [below of=B] {$X^3$};
 \node (D) [below of=C] {$X^4$};
 \node (E) [below of=D] {$X^5$};  
 \node (F) [label={[label distance=-1cm] \color{green}{Complete}}, below left of=E,left=1cm] {$X^6$};
 \node (G) [below right of=E, right=1cm] {$X^7$};
 \node (H) [below left of=G,left=1cm] {$X^8$};
 \node (I) [label={[label distance=-1cm] \color{red}{Closed}}, below right of=G, right=1cm] {$X^9$};
 \node (L) [label={[label distance=-1cm] \color{red}{Closed}}, below of=H] {$X^{10}$};


 \path (A) edge  (B);
 \path (B) edge (C);
 \path (C) edge (D);
 \path (D) edge (E);
 \path (E) edge  node [below=0.3cm, right=0.4cm]{PB-Rule}  (F)
        edge (G);
  \path (G) edge node [below=0.3cm, right=0.4cm] {PB-Rule} (H)
        edge  (I);          
 \path (H) edge node {E-Rule} (L);

\end{tikzpicture}

      

Any suggestion?

+3


source to share


1 answer


To place a label between siblings, you can use the syntax !0.5!

:

\begin{tikzpicture}[auto, node distance=1.3cm]
  \node (A) {$X^1$};
  \node (B) [below of=A] {$X^2$};
  \node (C) [below of=B] {$X^3$};
  \node (D) [below of=C] {$X^4$};
  \node (E) [below of=D] {$X^5$}; 
   \node (F) [label={[label distance=-1cm] \color{green}{Complete}}, below left of=E,left=1cm] {$X^6$};
  \node (G) [below right of=E, right=1cm] {$X^7$};
  \node (H) [below left of=G,left=1cm] {$X^8$};
  \node (I) [label={[label distance=-1cm] \color{red}{Closed}}, below right of=G, right=1cm] {$X^9$};
  \node (L) [label={[label distance=-1cm] \color{red}{Closed}}, below of=H] {$X^{10}$};

  \node (label1) at ($(F)!0.5!(G)$) {PB-Rule};
  \node (label2) at ($(H)!0.5!(I)$) {PB-Rule};

  \path (A) edge  (B);
  \path (B) edge (C);
  \path (C) edge (D);
  \path (D) edge (E);
  \path (E) edge (F);
  \path (E) edge (G);
  \path (G) edge (H);
  \path (G) edge (I);
  \path (H) edge node {E-Rule} (L);
\end{tikzpicture}

      



Note: you need the calc tikz library for this syntax.

enter image description here

+2


source







All Articles