# Centering vertically inside a block with figures

I want to center vertically different height figures inside the block they reside in.

I use the 'tikz-qtree' for the trees, and I want the '5' tree and the right arrow aligned vertically.

\documentclass[a4paper]{article}
\usepackage{mathtools}
\usepackage{tikz-qtree}

\begin{document}
\tikzset{every tree node/.style={minimum width=2em,draw,circle},
blank/.style={draw=none},
edge from parent/.style=
{draw, edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}},
level distance=1.5cm}

\begin{center}
\begin{tikzpicture}
\Tree
[.9
[.7 ]
\edge[blank]; \node[blank]{};
]
\end{tikzpicture},
\begin{tikzpicture}
\Tree
[.5 ]
\end{tikzpicture}
$\Longrightarrow$
\end{center}

\end{document}


-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Andrew Swann Apr 7 '14 at 9:23
PS please post complete compilabel code instead of a snippet. –  Andrew Swann Apr 7 '14 at 9:30
@AndrewSwann Done. Thanks for being nice! –  NightRa Apr 7 '14 at 9:34
You could apply a \raisebox{-6pt}{} around the tikzpicture pair, or conversely, a +6pt \raisebox to the \Longrightarrow. –  Steven B. Segletes Apr 7 '14 at 10:04

One way is to place each diagram in \vcenter:

\documentclass{article}

\usepackage{tikz,tikz-qtree}

\tikzset{blank/.style={white},every tree node/.style={draw,circle}}

\begin{document}
\begin{center}
$$\vcenter{\hbox{\begin{tikzpicture} \Tree [.9 [.7 ] \edge[blank]; \node[blank]{}; ] \end{tikzpicture}}}, \vcenter{\hbox{\begin{tikzpicture} \Tree [.5 ] \end{tikzpicture}}} \Longrightarrow$$
\end{center}
\end{document}


Another way is to specify the baseline option of each tikzpicture, see Aligning a Tikz Picture in line with the surrounding Text for example.

To pack the above solution in to a macro you could use

\usepackage{environ}
\NewEnviron{tikzcenter}{\ensuremath\vcenter{\hbox{\begin{tikzpicture}\BODY\end{tikzpicture}}}}


used as

\documentclass{article}

\usepackage{tikz,tikz-qtree}

\tikzset{blank/.style={white},every tree node/.style={draw,circle}}
\usepackage{environ}
\NewEnviron{tikzcenter}{\ensuremath\vcenter{\hbox{\begin{tikzpicture}\BODY\end{tikzpicture}}}}

\begin{document}
\begin{center}
$$\begin{tikzcenter} \Tree [.9 [.7 ] \edge[blank]; \node[blank]{}; ] \end{tikzcenter}, \begin{tikzcenter} \Tree [.5 ] \end{tikzcenter} \Longrightarrow$$
\end{center}
\end{document}

-
How can I make a macro to wrap all these things and not have to copy everything all the time? –  NightRa Apr 7 '14 at 9:38
I have now added an environment for this. –  Andrew Swann Apr 7 '14 at 10:07

Here is a tikz way.

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\begin{center}
\begin{tikzpicture}[baseline=(current bounding box.center)]     %%% this added
\Tree
[.9
[.7 ]
\edge[draw=none]; \node[draw=none]{};
]
\end{tikzpicture},
\Tree
[.5 ]
\end{tikzpicture}
$\Longrightarrow$
\end{center}
\end{document}


With adjustbox.

\documentclass{article}
\usepackage{tikz-qtree}
\usepackage{etoolbox}
\begin{document}
\begin{center}
\begin{tikzpicture}
\Tree
[.9
[.7 ]
\edge[draw=none]; \node[draw=none]{};
]
\end{tikzpicture}
,
\begin{tikzpicture}
\Tree
[.5 ]
\end{tikzpicture}
$\Longrightarrow$
\end{center}
\end{document}


-