Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

Current state

share|improve this question
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Andrew Swann Apr 7 at 9:23
    
PS please post complete compilabel code instead of a snippet. –  Andrew Swann Apr 7 at 9:30
    
@AndrewSwann Done. Thanks for being nice! –  NightRa Apr 7 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 at 10:04

2 Answers 2

up vote 2 down vote accepted

One way is to place each diagram in \vcenter:

Sample output

\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}
share|improve this answer
    
How can I make a macro to wrap all these things and not have to copy everything all the time? –  NightRa Apr 7 at 9:38
    
I have now added an environment for this. –  Andrew Swann Apr 7 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},
\begin{tikzpicture}[baseline]     %%% this added
\Tree
[.5 ]
\end{tikzpicture}
$\Longrightarrow$
\end{center}
\end{document}

enter image description here

With adjustbox.

\documentclass{article}
\usepackage{tikz-qtree}
\usepackage{adjustbox}
\usepackage{etoolbox}
\BeforeBeginEnvironment {tikzpicture}{\begin{adjustbox}{valign=m}}
\AfterEndEnvironment {tikzpicture}{\end{adjustbox}}
\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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.