Positioning a node relative to the center of another node in tikz

One way is to anchor the node to the south west (as you have done), then shift it to the left by the amount necessary to align the first zero:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{calc}
\usetikzlibrary{positioning}
\begin{document}

\newlength{\zerooffset}
\begin{frame}
  \begin{tikzpicture}[overlay,remember picture]
    \node[draw,fill=cyan!40,minimum size=1.2cm,rectangle,yshift=.5cm] at (current page.center) 
    (s1) {q};
    \setlength{\zerooffset}{\widthof{0}}%<=== get the width of the 0
    \node[draw=none,above= of s1,anchor=south west,xshift={\dimexpr-0.5\zerooffset-\pgfkeysvalueof{/pgf/inner xsep}}] (s2) {0 0 0 1 1 1};
    \draw[->] (s1) -- (s2);
  \end{tikzpicture}
\end{frame}
\end{document}

centered first zero

And if you want the arrow to be vertical:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\begin{document}

\newlength{\zerooffset}
\begin{frame}
  \begin{tikzpicture}[overlay,remember picture]
    \node[draw,fill=cyan!40,minimum size=1.2cm,rectangle,yshift=.5cm] at (current page.center) 
    (s1) {q};
    \setlength{\zerooffset}{\widthof{0}}%<=== get the width of the 0
    \node[draw=none,above= of s1,anchor=south west,xshift={\dimexpr-0.5\zerooffset-\pgfkeysvalueof{/pgf/inner xsep}}] (s2) {0 0 0 1 1 1};
    \draw[->] let \p1=(s1.north),\p2=(s2.south) in (\x1,\y1)--(\x1,\y2);%<=== vertical arrow
  \end{tikzpicture}
\end{frame}
\end{document}

centered with vertical arrow


Try this. I have split the node with the text into two, which allows to position them as required. Notice the \smallskipamount which corresponds to the space between the zeros.

Code:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{frame}
        \begin{tikzpicture}[overlay,remember picture]
        \node[draw,fill=cyan!40,minimum size=1.2cm,rectangle,yshift=.5cm] at (current page.center) (s1) {q};

        \node[draw=none,above=of s1] (s2) {0};
        \node[draw=none,right=\smallskipamount] at (s2) {0 0 1 1 1};

        \draw[->] (s1) -- (s2);
        \end{tikzpicture}
    \end{frame}
\end{document}

Result:

enter image description here

Tags:

Tikz Pgf