# How to fix a colliding arrow between two labelled box

Hi everyone and thanks for reading my post.

In a TikZ drawing, I have two boxes defined one above the other with \node[draw] type command. I also added boxed labels above each. The problem is that when drawing an arrow between the two boxes, only the coordinates of the basic box is considered, so the arrow croses the labels instead of stopping just before it.

I understand why TikZ does that, but how could I fix it? I tried to point to a (A2.label) node but it appears that it does not exist...

Below is my minimum working example and what it gives for now. Thank you for your help!

\documentclass[10pt]{standalone}
\usepackage[english]{babel}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

% BOX 1
\node[draw,text width=7cm,
label={[text width=7cm,fill=black!10,draw,minimum height=12pt]{\bfseries box 1}}
] (A1) at (0,0) {
some text for box 1
} ;

% BOX 2
\node[draw,text width=5cm,
label={[text width=5cm,fill=black!10,draw,minimum height=12pt]{\bfseries box 2}}
] (A2) [below of=A1,yshift=-4cm] {
some other text for box 2
} ;

% ARROW
\draw[->,>=latex] (A1) -- node[right] {test} (A2) ;

\end{tikzpicture}
\end{document}


A label is a node, too. So one possibility is to give it a name or alias, and draw the arrow to the label node.

\documentclass[10pt]{standalone}
\usepackage[english]{babel}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

% BOX 1
\node[draw,text width=7cm,
label={[text width=7cm,fill=black!10,draw,minimum height=12pt]{\bfseries box 1}}
] (A1) at (0,0) {
some text for box 1
} ;

% BOX 2
\node[draw,text width=5cm,
label={[text width=5cm,fill=black!10,draw,minimum
height=12pt,alias=stop here]{\bfseries box 2}}
] (A2) [below of=A1,yshift=-4cm] {
some other text for box 2
} ;

% ARROW
\draw[->,>=latex] (A1) -- node[right] {test} (stop here) ;

\end{tikzpicture}
\end{document}


Another way to achieve this output is to build a compound of A2 and the label node using the fit library.

\documentclass[10pt]{standalone}
\usepackage[english]{babel}

\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\begin{document}
\begin{tikzpicture}

% BOX 1
\node[draw,text width=7cm,
label={[text width=7cm,fill=black!10,draw,minimum height=12pt]{\bfseries box 1}}
] (A1) at (0,0) {
some text for box 1
} ;

% BOX 2
\node[draw,text width=5cm,
label={[text width=5cm,fill=black!10,draw,minimum
height=12pt,alias=include me]{\bfseries box 2}}
] (A2) [below of=A1,yshift=-4cm] {
some other text for box 2
} ;
\node[inner sep=0pt,fit=(A2) (include me)] (A2compound){};
% ARROW
\draw[->,>=latex] (A1) -- node[right] {test} (A2compound) ;

\end{tikzpicture}
\end{document}

• perfect, I didn't know about the alias thing, very handy! Thanks a lot :) – jeannej Mar 20 '19 at 23:59