0

Possible Duplicate:
Creating a node fitting the horizontal width of two other nodes

I want to draw a rectangle node whose width is determined by the extent of two other nodes. I know there is minimum width, but I find the extraction of x coordinates rather difficult. Is there an easy way to achieve the desired result?

\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}
    \begin{tikzpicture}
        \node[rectangle,draw] (a) {a};
        \node[rectangle,draw,right=0.2cm of a] (b) {b};
        \node[rectangle,draw,below=0.2cm of a.south west,anchor=north west] (ab) {ab};
    \end{tikzpicture}
\end{document}

Compilation result

How do I control the width of the "ab" node so that it is right-aligned with "b"?

(And, by the way, how do I control the height of the "a" node so that it matches the height of the "b" node? My workaround consists of using a \phantom{b} in such cases -- rather hackish...)

krlmlr
  • 12,530
  • Duplicate: http://tex.stackexchange.com/q/23480/8057 – krlmlr Jul 18 '12 at 02:55
  • 1
    Instead of \phantom{b} you should use \vphantom{b} as that won't effect horizontal spacing. Alternatively you could use a \strut. – Peter Grill Jul 18 '12 at 04:43
  • @user946850: I've edited my answer to http://tex.stackexchange.com/q/23480/8057 to also show an approach that calculates the necessary width first and then sets the new nodes minimum width to that value. – Jake Jul 18 '12 at 04:47
  • @PeterGrill: Could you please provide an example for \strut? – krlmlr Jul 18 '12 at 13:27
  • @user946850: See the difference between \fbox{a\strut}\fbox{b\strut} \fbox{a\vphantom{b}}\fbox{b} There is also a \mathstrut for use in math mode. – Peter Grill Jul 18 '12 at 21:24

0 Answers0