I am plotting some diagrams and encountered a problem. Here is my code

\usetikzlibrary{arrows.meta, positioning, quotes, shadows}

node distance = 25mm and 10mm, 
   box/.style = {draw, rounded corners, fill=blue!6, 
                 minimum width=22mm, minimum height=5mm, align=center},
   squarednode/.style={rectangle, draw=black!0, fill=blue!1, very thick, minimum size=1mm},
            > = {Straight Barb[angle=60:2pt 3]},
   bend angle = 15,
         auto = right,

\node (node1)  [box,draw,name path=node1]                     {\large{Heat} \\ \large{market}};
\node (node2)  [box,draw,name path=node2, above right=of node1]    {\large{Combined Heat and Power Plants, }\\\large{Power-to-Heat units}};
\node (node3)  [box, draw, name path=node3, below right=of node2]    {\large{Electricity} \\ \large{market}};
\node (node4)  [box, left =of node2]  {};

\path       [name path=node12]                      let \p1 = ($(node2)-(node1)$) 
             in       (node1)       ($(node1)!5pt!($(node1)+(-\y1,\x1)$)$)       to       +(\p1);
\path       [name path=node21]                      let \p1 = ($(node2)-(node1)$) 
             in       (node1)       ($(node1)!-5pt!($(node1)+(-\y1,\x1)$)$)      to       +(\p1);
\path       [name path=node23]                      let \p1 = ($(node3)-(node2)$) 
             in       (node2)       ($(node2)!5pt!($(node2)+(-\y1,\x1)$)$)       to       +(\p1);
\path       [name path=node32]                      let \p1 = ($(node3)-(node2)$) 
             in       (node2)       ($(node2)!-5pt!($(node2)+(-\y1,\x1)$)$)      to       +(\p1);             

\node       [name intersections={of=node1 and node12}]     (start) at (intersection-1){};
\draw       [<-,very thick,name intersections={of=node2 and node12}] 
            (start.center) -- node[text width=3.5cm,sloped,swap,midway,above, align=center] {1. Heat offer}  (intersection-1);
\node       [name intersections={of=node2 and node21}]     (start) at (intersection-1){};
\draw       [<-,very thick,name intersections={of=node1 and node21}] 
            (start.center) -- node[text width=3cm,sloped, align=center] {2. Heat dispatch and price} (intersection-1);
\node       [name intersections={of=node2 and node23}]     (start) at (intersection-1){};
\draw       [<-,very thick,name intersections={of=node3 and node23}] 
            (start.center) -- node[text width=3cm,sloped,swap,midway,above, align=center] {4. Electricity dispatch and price}  (intersection-1);
\node       [name intersections={of=node3 and node32}]     (start) at (intersection-1){};
\draw       [<-,very thick,name intersections={of=node2 and node32}] 
            (start.center) -- node[sloped] {3. Electricity offer} (intersection-1);
\draw       [->]  (node4) --node[text width=3cm, above, midway] {Electricity price forecast}  (node2);


First I plot some nodes, then I calculate distances to plot parallel lines as in https://tex.stackexchange.com/a/232828/262804. Then, I am plotting the text above the line as in https://tex.stackexchange.com/a/249540/262804 with the following line

\draw [->] (node4) --node[text width=3cm, above, midway] {Electricity price forecast} (node2);

And then I am getting this result

enter image description here

How can I make "Electricity price forecast" text node be always between node4 and node2 and never cross them?

  • 3
    You just have to let more space between those two nodes, for example by using \node (node4) [box, left = 3cm of node2] {};
    – SebGlav
    Commented Apr 30, 2022 at 12:36
  • Any news? Does received answer solve your problem?
    – Zarko
    Commented May 5, 2022 at 20:29

1 Answer 1


Huh, your MWE is very (to my opinion unnecessary) complex (consequently in it can be easily lost)

  • My suggestion is mostly off-topic -- possible solution is already mentioned in @SebGlav comment -- but seems to be better to increase common node distances, for example to node distance = 19mm and 17mm and at same time use smaller font size for edge quotes.
  • In your MWE preamble you load packages and libraries up to three times! Why? Sufficient is just once.
  • Please, in MWE preamble provide only to it relevant stuff, as is done in my answer.
  • Complexity of your MWE can reduced and make shorter by using transform canvas for inner edges in picture and quotes library for edge labels:

node distance = 19mm and 17mm,
   box/.style = {draw, rounded corners, fill=blue!6,
                 minimum width=22mm, minimum height=11mm, align=center},
every edge/.style = {draw, -{Straight Barb[angle=60:2pt 3]}, semithick},
every edge quotes/.style = {auto, align=center,

\node (n1)  [box] {Combined Heat\\ 
                    and Power Plants,\\
                    Power-to-Heat units};
\node (n2)  [box, left=of n1]   {};
\node (n3)  [box, below  left=of n1]    {Heat\\ market};
\node (n4)  [box, below right=of n1]    {Electricity\\ market};
\path   (n2) edge["Electricity\\price\\forecast"]   (n1)
        (n1) edge["1. Heat offer"]                  (n3.north)
        (n1) edge["3. Electricity\\offer"]          (n4.north)
\path[transform canvas={xshift=+9pt}]       
        (n3.north) edge["2. Heat dispatch\\ 
                        and price" ']               (n1);                 
\path[transform canvas={xshift=-9pt}]
        (n4.north) edge["4. Electricity\\ dispatch and\\ 
                        price" ']                   (n1);


You must log in to answer this question.

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