The use case I'm having is the following:
\documentclass{article}
\usepackage{amsmath}
\usepackage[showframe]{geometry}
\usepackage{qtree}
\begin{document}
\Tree [.A B C [.D E ] ]
\Tree [.F [.G H ] I ]
\Tree [.J [.K [.L M M ] N ] O ]
\Tree [.F [.G H ] I ]
\end{document}
which due to qtree
s clever horizontal alignment produces
Now, as qtree
is limited to 5 branches, I'm using tikz-qtree
and therefore essentially a tikzpicture:
\documentclass{article}
\usepackage{amsmath}
\usepackage[showframe]{geometry}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{center}
\begin{tikzpicture}
\Tree [.A B C [.D E ] ]
\end{tikzpicture}
\begin{tikzpicture}
\Tree [.F [.G H ] I ]
\end{tikzpicture}
\begin{tikzpicture}
\Tree [.J [.K [.L M M ] N ] O ]
\end{tikzpicture}
\begin{tikzpicture}
\Tree [.F [.G H ] I ]
\end{tikzpicture}
\end{center}
\end{document}
which produces
How can I achieve the same spacing as in qtree
? So that each space between two tikzpicture
s and to the borders is the same, without using any manual measurements. Also, alignment should be at the top, not bottom.
Best Answer
If you have many TikZ pictures you want align at the top you can use the
align at top
style defined asThe
\Tree
macros oftikz-qtree
check whether they are already in a PGF picture so you could simply writeand they would automatically align at the top.
But they are not spread along the horizontal space.
The alignment can be fixed by including
\hfill
s between the\Tree
s/the TikZ pictures. An additional\hfill
is needed before the first and the last element.To save typing I have introduced a environment
spreadTrees
that adds a\hfill
before every PGF/TikZ picture and appends a last\hfill\null
at the end of the environment. Thecenter
environment is included, though actually only needed for the vertical space the environment includes.You can do the same without the
center
environment (for floats). This is what thespreadTrees*
environment does. There is a slight different horizontal placement, though.\hspace*{\fill}
instead of\hfill\null
Here’s the definition of the environments according to the comment by Ignasi and the answer by egreg:
Code
Output