6

Assume there are two nodes A and B, with B below A. These nodes are of different width. Connecting A.south to B.north results in a slanted line. I wonder how I can connect A.south to B with the connection being vertical. I do not want to use A.south to, say, B.8 which results in a straight line however when the width of B changes the connection will not be straight anymore.

A MWE is as follows:

\documentclass[10pt]{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\tikzset{font=\Large,
every node/.style=
    {minimum height=8mm,
    draw=blue,
    very thick,
    },
data/.style = {draw, node distance=3cm}
    }

The line from A to B is vertical in the following example.


\begin{tikzpicture}
\node (a) {A};
\node[below right=of a] (c) {C};
\node[left=of c] (B) {BBBBBBBBBBBBBBBBBB};
\draw[->][very thick](a.south) -- (B.8);
\end{tikzpicture}

\medskip 

The line from A to B is not vertical in the following example.

\medskip

\begin{tikzpicture}
\node (a) {A};
\node[below right=of a] (c) {C};
\node[left=of c] (B) {BBBBBBBBBBBBBBBBBBBBB};
\draw[->][very thick](a.south) -- (B.8);
\end{tikzpicture}

\end{document}
Reza
  • 2,301

1 Answers1

16

You can use the perpendicular coordinate system; for example

\draw (A.south) -- (A.south|-B.north);

will draw a line from A.south to the point that has the same x-coordinate as A.south and the same y-coordinate as B.north. A little example:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node[draw] at (0,0) (A) {short text};
\node[draw] at (0.2,-2) (B) {Some longer text};
\draw[green] (A.south) -- (B.north);
\draw[red] (A.south) -- (A.south|-B.north);
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128