[Tex/LaTex] Aligning nodes with TikZ

nodestikz-pgfvertical alignment

Consider this:

misaligned nodes

There are several problems:

  1. The \exists operator is not horizontaly aligned with the following node (a,b).
  2. There is too little space between foobar and the node below it and between the (a,b) node and the nodes below it.
  3. The right arrow is not horizontally aligned with the preceding and following nodes. (I know that I can draw arrows with TikZ, this is just a placeholder.)

Any help on resolving these issues is greatly appreciated. Here is the code at present.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning,fit}

\begin{document}

\begin{tikzpicture}[
  node distance=3mm and 3mm,
  drs/.style={draw, rectangle split, rectangle split parts=2}
  ]
  \node[drs,align=left]
    { foo
      \nodepart{two}

        foobar \
        \tikz{
          \node (operator) {$\exists$};
          \node[drs,right=of operator]{
            a%
            \nodepart{two}{
              b%
            }
          };
        } \
        \tikz{
          \node[drs] (left side)
            { 1%
              \nodepart{two}
                2%
            };
          \node[right=of left side] (operator) {$\rightarrow$};
          \node[drs,right=of operator] (right side)
            { 3%
              \nodepart{two}
                4 \\
                5 \\
                6%
            };
        }
    };
\end{tikzpicture}


\end{document}

Best Answer

Problems 1) and 3): you can control the alignment using the mid anchor of nodes. Problem 2): you can use the optional argument of the line changing command \\; here's a modified version of your code, feel free to change the lengths according to your needs:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning,fit}

\begin{document}

\begin{tikzpicture}[
  drs/.style={draw, rectangle split, rectangle split parts=2}
  ]
  \node[drs,align=left]
    { foo
      \nodepart{two}
        foobar \\[.5em]
        \tikz{
          \node (operator) {$\exists$};
          \node[drs,right=2mm of operator.mid]{
            a%
            \nodepart{two}{
              b%
            }
          };
        } \\[.5em]
        \tikz{
          \node (operator) {$\rightarrow$};
          \node[drs,left=4mm of operator.mid] (left side)
            { 1%
              \nodepart{two}
                2%
            };
          \node[drs,right=4mm of operator.mid] (right side)
            { 3%
              \nodepart{two}
                4 \\
                5 \\
               6%
            };
        }
    };
\end{tikzpicture}

\end{document}