4
\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?

7

Edit: Added manual text alignment adjustment

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

premier-code

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}

corrige

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.