0

I would like to draw a horizontal-vertical path between two nodes, with different radii of rounded corners.

Here's my original code (single-radius):

\documentclass[tikz]{standalone}

\usetikzlibrary{fit,arrows.meta,mindmap,shadows,backgrounds,calc,positioning,shapes.misc}
\tikzset{Arrow/.style={-{stealth},very thick}}

\begin{document}

\begin{tikzpicture} [every node/.style={draw,rectangle,rounded corners,minimum width=22mm},
    every text node part/.style={align=center}]
\node (A) at (0,0) {A};
\node (B) at (5,5) {B};

\draw[Arrow,rounded corners=5pt]
    % start at source
    (A)
    % go right and up to anchor
    -| ($ (B.south) - (18.5mm,3mm) $)
    % go right and up to target
    -| ([xshift=-7mm]B.south)
    ;
\end{tikzpicture}

\end{document}

Results:

enter image description here

Now I would like the first turn to have a larger radius. The expected results should look like the following (please ignore the imperfections due to my bad GIMP skills):

enter image description here

I followed this answer to set a different radius for the first turn:

\documentclass[tikz]{standalone}
    
\usetikzlibrary{fit,arrows.meta,mindmap,shadows,backgrounds,calc,positioning,shapes.misc}
\tikzset{Arrow/.style={-{stealth},very thick}}

\begin{document}

\begin{tikzpicture} [every node/.style={draw,rectangle,rounded corners,minimum width=22mm},
    every text node part/.style={align=center}]
\node (A) at (0,0) {A};
\node (B) at (5,5) {B};

\draw[Arrow,rounded corners=5pt]
    % start at source
    (A)
    % go right and up to anchor
        { [rounded corners=30pt]
        -| ($ (B.south) - (18.5mm,3mm) $)
        }
    % go right and up to target
    -| ([xshift=-7mm]B.south)
    ;
\end{tikzpicture}

\end{document}

Results are not as expected:

enter image description here

Thank you very much in advance for your help!

1 Answer 1

2

You have three turns, but only two are explicit. TikZ intuits the third.

\documentclass[tikz]{standalone}

\usetikzlibrary{fit,arrows.meta,mindmap,shadows,backgrounds,calc,positioning,shapes.misc}
\tikzset{Arrow/.style={-{stealth},very thick}}

\begin{document}

\begin{tikzpicture} [every node/.style={draw,rectangle,minimum width=22mm},
    every text node part/.style={align=center}]
\node (A) at (0,0) {A};
\node (B) at (5,5) {B};

\draw[Arrow,rounded corners=30pt]
    % start at source
    (A)
    % go right and up to midpoint
    -| ($ (B.south) - (18.5mm,2.5) $)
    % got up and right to the anchor
    [rounded corners=5pt]
    |- ($ (B.south) - (12mm,3mm) $)
    % go right and up to target
    -| ([xshift=-7mm]B.south)
    ;
\end{tikzpicture}

\end{document}

demo


This version uses corners instead of midpoints.

\documentclass[tikz]{standalone}

\usetikzlibrary{fit,arrows.meta,mindmap,shadows,backgrounds,calc,positioning,shapes.misc}
\tikzset{Arrow/.style={-{stealth},very thick}}

\begin{document}

\begin{tikzpicture} [every node/.style={draw,rectangle,minimum width=22mm},
    every text node part/.style={align=center}]
\node (A) at (0,0) {A};
\node (B) at (5,5) {B};

\coordinate (AB) at ($ (B.south) - (18.5mm,3mm) $); % for simplicity
\coordinate (BB) at ([xshift=-7mm]B.south);

\draw[Arrow,rounded corners=30pt]
    % start at source
    (A) -- (A -| AB) % first corner
    [rounded corners=5pt]
     -- (AB) -- (AB -| BB) -- (BB);
\end{tikzpicture}

\end{document}
9
  • Woah, why didn't I think about this before? Perfect answer! Thank you very much!
    – f10w
    Commented Jul 1, 2020 at 13:32
  • Unfortunately this solution is not generic :( I changed the second to to \node (B) at (5,2.5) {B}; and couldn't find parameters that give an acceptable result :( Could you please have a look?
    – f10w
    Commented Jul 1, 2020 at 14:20
  • To find a midpoint, add the coordinates of the corners and divide by 2, or use (A!0.5!B) (calc tikzlibrary). Commented Jul 1, 2020 at 22:11
  • Works perfectly! Thank you so much!
    – f10w
    Commented Jul 3, 2020 at 0:47
  • Oops, make that ($(A)!0.5!(B)$). Commented Jul 3, 2020 at 0:52

You must log in to answer this question.

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