8

I have a (TikZ) diagram with several "blocks" of text connected by arrows. For reasons the (centers of the) blocks are not precisely horizontally aligned, but I'd still like my vertical arrows to be perfectly, well, vertical. Example:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \node[rectangle, draw] (a) at (0,0) {Some rather long text};
  \node[rectangle, draw] (b) at (.5,-2) {Even more text};
  \path[->] (a) edge (b);
  \path[red, ->] (a.315) edge (b.130);
\end{tikzpicture}
\end{document}

MWE

Instead of the black arrow, I'd prefer the red one which I've created by fiddling around with stupid numbers. Hence:

Is there a way to create, automatically, instead of the black arrow-between-centers, an arrow which is (1) perfectly vertical and (2) intersects the original arrow roughly at its center?

Uli Fahrenberg
  • 339
  • 1
  • 6

2 Answers2

6

You can specify the horizontal and vertical position in terms of nodes.

vertical arrow

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \node[rectangle, draw] (a) at (0,0) {Some rather long text};
  \node[rectangle, draw] (b) at (.5,-2) {Even more text};
  \draw[->] (b|-a.south) -- (b);
\end{tikzpicture}
\end{document}
TeXnician
  • 33,589
  • Nice (+1)... I think that the OP woyld like to use anchor=east too in order to not calculating manually the horizontal alignment. So, \documentclass[tikz]{standalone} \begin{document} \tikzset{mynode/.style={rectangle,draw,anchor=east}} \begin{tikzpicture} \node[mynode] (a) at (0,0) {Some rather long text}; \node[mynode] (b) at (0,-2) {Even more text}; \draw[->] (b|-a.south) -- (b); \end{tikzpicture} \end{document} would be an easier way. – koleygr Nov 14 '18 at 14:58
5

Or, if you want the arrow to be in the center,

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \node[rectangle, draw] (a) at (0,0) {Some rather long text};
  \node[rectangle, draw] (b) at (.5,-2) {Even more text};
  \path (a) -- (b) coordinate[midway] (aux);
  \draw[->] (a.south -| aux) -- (b.north -| aux);
\end{tikzpicture}
\end{document}

enter image description here