2

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

3
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Apr 7, 2014 at 9:23
  • PS please post complete compilabel code instead of a snippet. Apr 7, 2014 at 9:30
  • You could apply a \raisebox{-6pt}{} around the tikzpicture pair, or conversely, a +6pt \raisebox to the \Longrightarrow. Apr 7, 2014 at 10:04

2 Answers 2

2

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}
2
  • How can I make a macro to wrap all these things and not have to copy everything all the time?
    – NightRa
    Apr 7, 2014 at 9:38
  • I have now added an environment for this. Apr 7, 2014 at 10:07
3

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .