[Tex/LaTex] How to get TikZ nodes not to change alignment

arraysmatricesnodestikz-pgfvertical alignment

I'm still working on rendering a nice block matrix. I've been using BMAT but it is irrelevant for the question at hand. I want to connect various entries in an array/matrix/BMAT by lines, and I'm using TikZ for that. However, I've run into this problem: When I surround an entry with a TikZ node (for drawing a path later), it changes the vertical alignment and basically screws everything up.

Here's a MWE:


 2 & \tikz \node {$0$}; & \frac{2}{3} \\
 0 & \frac{4}{3} & 0 \\
 -\frac{2}{3} & \tikz \node [inner sep=0pt,outer sep=0pt]{$0$}; & 
   \tikz \node [inner sep=0pt,outer sep=0pt]{$\frac{6}{5}$}; \\
 0 & -\frac{4}{5} & 0 \\


With output:

matrix with mis-aligned entries

As you can see, The entries that have nodes around them are vertically mismached and differently aligned from the others. Setting outer sep and inner sep to zero doesn't help….

Any ideas?

Best Answer

You could use the \matrix command provided by the pgf/tikZ package. See the sample below for some inspiration.


    \begin{tikzpicture}[baseline=(current bounding box.west)]
      \matrix [%
        matrix of math nodes,
        text centered
      ] {%
        2 & 0 & \frac{2}{3} \\
        0 & \frac{4}{3} & 0 \\
        -\frac{2}{3} & 0 & -\frac{4}{5} \\