3

MWE:

% !TEX program = xelatex

\documentclass{book}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}

\begin{document}

    \begin{tikzpicture}%
        \node (first)    {First};
        \node (second)   [below right=1cm of first] {Second};

        \begin{pgfonlayer}{bg}%
            \draw [->,rounded corners] (first.east) -| ($ (first.east-|second.north) + (0,-5mm) $) |- (second.north);
            \draw [->,rounded corners] (second.west) -| ($ (second.west-|first.south) + (0,5mm) $) |- (first.south);
        \end{pgfonlayer}
    \end{tikzpicture}%

\end{document}

Result:

enter image description here

The arrow from second to first is rendered back to front and I can't figure out why. Can anyone enlighten me?

NOTE: if I disable rounded corners for that line then it renders the arrow correctly:

enter image description here

UPDATE: I can get it to render almost correctly by flipping the arrow head:

\draw [-<,rounded corners] (second.west) -| ($ (second.west-|first.south) + (0,5mm) $)  |- (first.south);

Which displays:

enter image description here

However, now the arrow head is too close to the node's text.

Kent Boogaart
  • 664
  • 4
  • 15

1 Answers1

4

Has to do with the fact that you're using a |- path specification, replace the last |- with -- and it works fine. I.e. instead of

\draw [->,rounded corners] (second.west) -| ($ (second.west-|first.south) + (0,5mm) $) |- (first.south);

use

\draw [->,rounded corners] (second.west) -| ($ (second.west-|first.south) + (0,5mm) $) -- (first.south);

But what's the point of the intermediate coordinate anyway, why don't you just do this?

\draw [->,rounded corners] (first) -| (second);
\draw [->,rounded corners] (second) -| (first);

enter image description here

\documentclass{book}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}

\begin{document}

    \begin{tikzpicture}%
        \node (first)    {First};
        \node (second)   [below right=1cm of first] {Second};

        \begin{pgfonlayer}{bg}%
            %\draw [->,rounded corners] (first.east) -| ($ (first.east-|second.north) + (0,-5mm) $) |- (second.north);
            %\draw [->,rounded corners] (second.west) -| ($ (second.west-|first.south) + (0,5mm) $) -- (first.south);

            \draw [->,rounded corners] (first) -| (second);
            \draw [->,rounded corners] (second) -| (first);
        \end{pgfonlayer}
    \end{tikzpicture}%

\end{document}
Torbjørn T.
  • 206,688
  • Ah, thanks. I was extrapolating from a more complicated source where I needed a waypoint, and I wasn't aware of the simpler syntax – Kent Boogaart Mar 08 '18 at 09:29