# fit does not respect relative positioning

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}
\node[name=a] {longa};
\node[name=b, below=of a] {longb};
\node[name=c, below=of b] {longc};
\node[name=talld, right=of c, fit=(a)(c), draw] {talld};
\end{tikzpicture}
\end{document}


Now talld overlaps the leftmost text. If I remove the fit=(a)(c) it shifts talld appropriately. How do I make fit respect relative positioning?

You say that the code that correctly places the nodes produces this:

But you want the right node to be as big as the other three combined.

Since tikz processes instructions in the order they are read, simply reverse the instructions you have written by first fiting the node around the other three:

write fit=(a)(c), right=of c, instead of right=of c, fit=(a)(c)

As longb is in the center, just place it on this right: fit=(a)(c), right=of b

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}
\node[name=a,draw] {longa};
\node[name=b,draw, below=of a] {longb};
\node[name=c,draw, below=of b] {longc};
\node[name=talld, fit=(a)(c), right=of b,draw,text height=55pt,inner sep=0pt,outer sep=0pt] {talgd};
\end{tikzpicture}
\end{document}


I've traced every node to make sure everything is done the way you want it.

• Thank you, this works and makes sense except now talld's text isn't centered in its rectangle! – enthdegree Aug 6 '18 at 18:21
• Indeed, I had not paid attention to it. You can manually adjust the text. i edited the solution. – AndréC Aug 6 '18 at 20:21