1

After using relative positioning in TikZ, I wish to displace the note by x units on the right to achieve this.

enter image description here

I found this answer Move a tikz node somewhat below in relative positioning helpful. But any combination of x and y in the node is not helping here.

Is there an easy way to do this.

I get the below result:

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{backgrounds}
\usetikzlibrary{fit}
\usetikzlibrary{decorations.pathmorphing}

\tikzset{squarenode/.style = {
    shape  = rectangle,
    fill   = gray!50,
    draw   = black,
    thick,
    minimum height = 1cm,
    minimum width  = 1cm
}}

\tikzset{circlenode/.style = {
    shape  = circle,
    fill   = blue!20,
    draw   = blue,
    thick,
    minimum size = 1cm
}}

\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}

\begin{document}
\begin{tikzpicture}
  [>=stealth']
  %\draw[My Grid] (-5,-5) grid (15,15);
  \node (r1) at (-4,4) [squarenode] {r1};
  \node[right=4cm of r1] (r2) [squarenode] {r2};
  \node[below=3cm of r1] (r3) [squarenode] {r3};
  \node[right=4cm of r3] (r4) [squarenode] {r4};
  \node[right=1.5cm of r1] (s2) [circlenode] {s2};
  \node[above=1cm of s2] (s1) [circlenode] {}; %s1
  \node[below=1cm of s2] (s3) [circlenode] {s3}; %s3
  \node[above=1ex of s3,red] {$s \leq 3$};
  \node[right=1.5cm of r3] (s4) [circlenode] {s4};
  \node[below=1cm of s4] (s5) [circlenode] {}; %s5
  \draw[fill=black] (s1.center) circle [radius=0.1cm];
  \draw[fill=black] (s5.center) circle [radius=0.1cm];
  \draw[->] (r1) -- (s2);
  \draw[->] (s2) -- (r2);
  \draw[->] (r3) -- (s4);
  \draw[->] (s4) -- (r4);
  \draw[->] (s1) to [out=180,in=90] (r1);
  \draw[->] (r1) to [out=-90,in=180] (s3);
  \draw[->] (s3) to [out=0,in=-90] (r2);
  \draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
  \draw[->] (r3) to [out=90,in=180] (s3);
  \draw[->] (s3) to [out=0,in=90] (r4);
  \draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
  \draw[->] (s5) to [bend left=45] (r3);
  \begin{scope}[on background layer]
    \node [fill=gray!15,rounded corners,fit=(s1) (s3) (s5) (r1) (r2)] (R1) {};
  \end{scope}

  \begin{scope}[xshift=10cm]
    \node (r1) at (-4,4) [squarenode] {r1};
    \node[right=4cm of r1] (r2) [squarenode] {r2};
    \node[below=3cm of r1] (r3) [squarenode] {r3};
    \node[right=4cm of r3] (r4) [squarenode] {r4};
    \node[right=1.5cm of r1] (s2) [circlenode] {s2};
    \node[above=1cm of s2] (s1) [circlenode] {}; %s1
    \node[below left=1.8cm of s2,] (s3) [circlenode] {s3}; %s3
    \node[right=1.5cm of r3] (s4) [circlenode] {s4};
    \node[below=1cm of s4] (s5) [circlenode] {}; %s5
    \draw[fill=black] (s1.center) circle [radius=0.1cm];
    \draw[fill=black] (s5.center) circle [radius=0.1cm];
    \draw[->] (r1) -- (s2);
    \draw[->] (s2) -- (r2);
    \draw[->] (r3) -- (s4);
    \draw[->] (s4) -- (r4);
    \draw[->] (s1) to [out=180,in=90] (r1);
    \draw[->] (r1) to [out=-90,in=180] (s3);
    \draw[->] (s3) to [out=0,in=-90] (r2);
    \draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
    \draw[->] (r3) to [out=90,in=180] (s3);
    \draw[->] (s3) to [out=0,in=90] (r4);
    \draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
    \draw[->] (s5) to [bend left=45] (r3);
        \begin{scope}[on background layer]
            \node [fill=gray!15,rounded corners,fit=(s1) (s3) (s5) (r1) (r2)] (R2) {};
        \end{scope}
  \end{scope}

  \draw[shorten >=1mm,-to,thick,decorate,decoration={snake,amplitude=.4mm,segment length=2mm,pre=moveto,pre length=1mm,post length=2mm}] (R1) -- (R2) node [above=1mm,midway,text width=3cm,align=center] {replacement of the \textcolor{red}{capacity} by \textcolor{red}{two places}};

\end{tikzpicture}
\end{document} 
0

1 Answer 1

2

Like this?

The positioning library allows you to place nodes relative to others. When writing:

\node[below left=1.2cm and 0cm of s2,] 

the two dimensions each act on the position key :

  • the first dimension (1.2 cm) acts only on the first positioning (here below)
  • the second dimension (0 cm) only affects the second positioning (here left).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{backgrounds}
\usetikzlibrary{fit}
\usetikzlibrary{decorations.pathmorphing}

\tikzset{squarenode/.style = {
    shape  = rectangle,
    fill   = gray!50,
    draw   = black,
    thick,
    minimum height = 1cm,
    minimum width  = 1cm
}}

\tikzset{circlenode/.style = {
    shape  = circle,
    fill   = blue!20,
    draw   = blue,
    thick,
    minimum size = 1cm
}}

\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}

\begin{document}
\begin{tikzpicture}
  [>=stealth']
  %\draw[My Grid] (-5,-5) grid (15,15);
  \node (r1) at (-4,4) [squarenode] {r1};
  \node[right=4cm of r1] (r2) [squarenode] {r2};
  \node[below=3cm of r1] (r3) [squarenode] {r3};
  \node[right=4cm of r3] (r4) [squarenode] {r4};
  \node[right=1.5cm of r1] (s2) [circlenode] {s2};
  \node[above=1cm of s2] (s1) [circlenode] {}; %s1
  \node[below=1cm of s2] (s3) [circlenode] {s3}; %s3
  \node[above=1ex of s3,red] {$s \leq 3$};
  \node[right=1.5cm of r3] (s4) [circlenode] {s4};
  \node[below=1cm of s4] (s5) [circlenode] {}; %s5
  \draw[fill=black] (s1.center) circle [radius=0.1cm];
  \draw[fill=black] (s5.center) circle [radius=0.1cm];
  \draw[->] (r1) -- (s2);
  \draw[->] (s2) -- (r2);
  \draw[->] (r3) -- (s4);
  \draw[->] (s4) -- (r4);
  \draw[->] (s1) to [out=180,in=90] (r1);
  \draw[->] (r1) to [out=-90,in=180] (s3);
  \draw[->] (s3) to [out=0,in=-90] (r2);
  \draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
  \draw[->] (r3) to [out=90,in=180] (s3);
  \draw[->] (s3) to [out=0,in=90] (r4);
  \draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
  \draw[->] (s5) to [bend left=45] (r3);
  \begin{scope}[on background layer]
    \node [fill=gray!15,rounded corners,fit=(s1) (s3) (s5) (r1) (r2)] (R1) {};
  \end{scope}

  \begin{scope}[xshift=10cm]
    \node (r1) at (-4,4) [squarenode] {r1};
    \node[right=4cm of r1] (r2) [squarenode] {r2};
    \node[below=3cm of r1] (r3) [squarenode] {r3};
    \node[right=4cm of r3] (r4) [squarenode] {r4};
    \node[right=1.5cm of r1] (s2) [circlenode] {s2};
    \node[above=1cm of s2] (s1) [circlenode] {}; %s1
    \node[below left=1.2cm and 0cm of s2,] (s3) [circlenode] {s3bis}; %s3
    \node[right=1.5cm of r3] (s4) [circlenode] {s4};
    \node[below=1cm of s4] (s5) [circlenode] {}; %s5
    \draw[fill=black] (s1.center) circle [radius=0.1cm];
    \draw[fill=black] (s5.center) circle [radius=0.1cm];
    \draw[->] (r1) -- (s2);
    \draw[->] (s2) -- (r2);
    \draw[->] (r3) -- (s4);
    \draw[->] (s4) -- (r4);
    \draw[->] (s1) to [out=180,in=90] (r1);
    \draw[->] (r1) to [out=-90,in=180] (s3);
    \draw[->] (s3) to [out=0,in=-90] (r2);
    \draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
    \draw[->] (r3) to [out=90,in=180] (s3);
    \draw[->] (s3) to [out=0,in=90] (r4);
    \draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
    \draw[->] (s5) to [bend left=45] (r3);
        \begin{scope}[on background layer]
            \node [fill=gray!15,rounded corners,fit=(s1) (s3) (s5) (r1) (r2)] (R2) {};
        \end{scope}
  \end{scope}

  \draw[shorten >=1mm,-to,thick,decorate,decoration={snake,amplitude=.4mm,segment length=2mm,pre=moveto,pre length=1mm,post length=2mm}] (R1) -- (R2) node [above=1mm,midway,text width=3cm,align=center] {replacement of the \textcolor{red}{capacity} by \textcolor{red}{two places}};

\end{tikzpicture}
\end{document}

screenshot

2
  • Yes. Can you please explain the solution . Commented Mar 5, 2019 at 16:49
  • 1
    It is done ! Is that clearer ? Is that better?
    – AndréC
    Commented Mar 5, 2019 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .