I am trying to draw a straight arrow from one shape to another, two rectangles precisely. I have an MWE below, but the arrow from rectangle B meets rectangle A at an angle instead of at 90 degrees.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\tikzstyle{block}=[draw,shape=rectangle,minimum width=3.5em,text width=1.7cm,align=center,minimum height=1.2cm, node distance=3cm]
\node[block] (A) at (0,0) {A};
\node[block,right of=A] (B) {B};
\draw[->] ([yshift=-2em] B) -- ([yshift=-2em] A);
\end{tikzpicture}
\end{document}
What I am trying to achieve:
Best Answer
This looks like a bug for me.
In a strange way if we use
([transform] A)
whenA
is a node, the anchor to, or from,A
is calculated before the transformation, and the nodeA
is transformed only afterwards.In your example :
A
is calculated, and not to([yshift=-2em] A)
, from the shiftedB
(or more precisely from([yshift=-2em] B.center)
);B
is calculated, not from([yshift=-2em] B)
, to the calculated anchor ofA
.Here is an illustration of this.
In conclusion : We can't transform nodes like this, only "real" coordinates are transformed.
Workaround: You can use
transform canvas
to do your shifts like this :In your particular MWE a workaround will be also to specify the anchors like this :
UPDATE: Actually
([transformed] A)
looks to have a "double nature" : as a coordinate it is the same as([transformed] A.center)
and as a node it is the same as(A)
. Here is one example that shows this "double behavior" of coordinate transformed nodes.