# Center a Node Vertically TikZ

I'm using TikZ to create the following drawing:

So far so good, but now I'd like to center the node with the gray background vertically. Here's its code:

\setlength{\arraycolsep}{2pt}
\draw[xshift=-3cm,yshift=(current bound box.center)]
node[align=left,right,rounded corners,fill=black!10,inner sep=1ex]
{$\left\{ \begin{array}{llc} h &=& \overline{AF}\\ l &=& \overline{BF}\\ l'&=& \overline{AB}\\ d &=& \overline{CE} \end{array} \right.$};


It's being pushed to the left by xshift, thus I could equally use yshift with a measure to center it. However, is it possible to do it dynamically (by retrieving the bounding box height)? That's, if the drawing grows, it will remain centered.

-
Please add a minimal working example (MWE) that illustrates your problem. While code snippets are useful in analysis, MWE will save time for those who try to find a solution for you. – Harish Kumar Jun 10 '12 at 1:22
@HarishKumar Certainly, sorry for that and thanks. I thought it would be simple enough and the node code would be only part needed, but that's no excuse… – sidyll Jun 10 '12 at 2:22

You could use the positioning library and then use the left=of <node identifier> for positioning the node containing the array; I added some more files to the array to see the effect:

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

\begin{document}

\begin{tikzpicture}
\setlength{\arraycolsep}{2pt}
\node[draw,fill,circle,inner sep=1pt,label=right:$C$] at (3,0) (c) {};
\node[align=left,rounded corners,fill=black!10,inner sep=1ex,left=of c]
{$\left\{ \begin{array}{llc} h &=& \overline{AF}\\ l &=& \overline{BF}\\ l'&=& \overline{AB}\\ d &=& \overline{CE}\\ h &=& \overline{AF}\\ l &=& \overline{BF}\\ h &=& \overline{AF}\\ l &=& \overline{BF}\\ \end{array} \right.$};
\end{tikzpicture}

\end{document}


More generally (as Caramdir has suggested), you can use left=of current bounding box.center:

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

\begin{document}

\begin{tikzpicture}
\setlength{\arraycolsep}{2pt}
\node[draw,fill,circle,inner sep=1pt,label=right:$C$] at (3,0) (c) {};
\node[align=left,rounded corners,fill=black!10,inner sep=1ex,left=of current bounding box.center]
{$\left\{ \begin{array}{llc} h &=& \overline{AF}\\ l &=& \overline{BF}\\ l'&=& \overline{AB}\\ d &=& \overline{CE}\\ h &=& \overline{AF}\\ l &=& \overline{BF}\\ h &=& \overline{AF}\\ l &=& \overline{BF}\\ \end{array} \right.$};
\end{tikzpicture}

\end{document}

-
More generally, left= of current bound box.west is I think what the OP wants. – Caramdir Jun 10 '12 at 1:38
@Caramdir yes, I'll add this to my answer. – Gonzalo Medina Jun 10 '12 at 1:45
Thanks Mr. Medina, I still learning how to use TikZ properly and every advice such as about the positioning library (which was new to me) is quite valuable. Also thanks @Caramdir for the second solution! – sidyll Jun 10 '12 at 2:31

It's possible to avoid the positioning library :

1) Align with (C)

 \node[align=left,rounded corners,
fill=black!10,inner sep=1ex,anchor=east] at ([xshift=-2cm]c) {....


2) Align with (current bounding box)

  \node[align=left,rounded corners,fill=black!10,
inner sep=1ex,anchor=east] at (current bounding box.west) {...

-