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 draw some trees in tikz and align them like this (mockup):

mockup

Note that the enumerations align to the top.

Ideally, this should "just work", breaking lines as needed, and automatically sizing the width of all these graphics.

My best take so far is this:

screenshot

The numbers don't line up, and I could not convince them to do so with the [t] argument. Also, I had to specify each width manually:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage{tikz-qtree}

\newenvironment{tikztree}
{
    \tikzpicture[sibling distance=1cm, level distance=1cm, baseline]
    \tikzstyle{every node}=[draw, circle, fill=black, inner sep=0pt, minimum size=2mm]
}{
    \endtikzpicture
}

\begin{document}

    \begin{enumerate}
        \begin{minipage}{2cm}\item \begin{tikztree}[baseline]\Tree[.{} ];\end{tikztree}\end{minipage}
        \begin{minipage}{2cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} ] ];\end{tikztree}\end{minipage}
        \begin{minipage}{3cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} ] [.{} ] ];\end{tikztree}\end{minipage}
        \vspace{5ex}

        \begin{minipage}{4cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} [.{} ] [.{} ] ] [.{} ] ];\end{tikztree}\end{minipage}
        \begin{minipage}{2cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} [.{} ] ] ];\end{tikztree}\end{minipage}
        \begin{minipage}{3cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} [.{} ] [.{} ] ] ];\end{tikztree}\end{minipage}
    \end{enumerate}

\end{document}

What's the best way to accomplish that?

share|improve this question
    
Why not have everything in the tikzpicture? That would be easier. Or would you rather not have that? –  zeroth Dec 3 '13 at 20:17
    
I simply don't know how to get automatic line-breaking and enumeration in tikz. –  fefrei Dec 3 '13 at 20:24
    
Why do you need the option [baseline] for the tikztree environment? Also, \tikzstyle is considered obsolete, \tikzset in recommended. See tex.stackexchange.com/questions/52372/… –  Kevin C Dec 4 '13 at 1:02
    
Baseline sets the baseline to the top, so that the \item ends up on top. Thanks for the \tikzstyle hint! –  fefrei Dec 4 '13 at 9:40
    
Oops, you meant that baseline. I forgot the remove that while building the MWE. –  fefrei Dec 4 '13 at 16:19

4 Answers 4

up vote 3 down vote accepted

You can use the same approach with minipages. Give same (suitable) width to all minipages and use \hfills.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage{tikz-qtree}

\newenvironment{tikztree}
{
    \tikzpicture[sibling distance=1cm, level distance=1cm, baseline]
    \tikzstyle{every node}=[draw, circle, fill=black, inner sep=0pt, minimum size=2mm]
}{
    \endtikzpicture
}

\begin{document}

    \begin{enumerate}
        \begin{minipage}[t]{3cm}\item \begin{tikztree}[baseline]\Tree[.{} ];\end{tikztree}\end{minipage}\hfill
        \begin{minipage}[t]{3cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} ] ];\end{tikztree}\end{minipage}\hfill
        \begin{minipage}[t]{3cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} ] [.{} ] ];\end{tikztree}\end{minipage}
        \vspace{5ex}

        \begin{minipage}[t]{3cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} [.{} ] [.{} ] ] [.{} ] ];\end{tikztree}\end{minipage}\hfill
        \begin{minipage}[t]{3cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} [.{} ] ] ];\end{tikztree}\end{minipage}\hfill
        \begin{minipage}[t]{3cm}\item \begin{tikztree}[baseline]\Tree[.{} [.{} [.{} ] [.{} ] ] ];\end{tikztree}\end{minipage}
    \end{enumerate}

\end{document}

enter image description here

Response to the comments:

We need [t] specifier so as to make all trees aligned at the top without them the trees will be aligned at the center (vertically). Further, \hfill will ensure that the items are equally distributed horizontally and hence are aligned.

share|improve this answer
    
I accepted your answer, since it seems to be the simplest fix, without further dependencies. Is there an easy explanation why you need both [t] and \hfill? –  fefrei Dec 4 '13 at 10:05
    
@fefrei Thanks and I added some clarifications. Feel free if anything is needed more. :-) –  Harish Kumar Dec 4 '13 at 11:59

Here is a quick solution using the multienumerate package. It is not the most robust package but does the trick. Wait for other solutions and compare.

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage{tikz-qtree}

\newenvironment{tikztree}
{
    \tikzpicture[sibling distance=1cm, level distance=1cm, baseline]
    \tikzstyle{every node}=[draw, circle, fill=black, inner sep=0pt, minimum size=2mm]
}{
    \endtikzpicture
}
\usepackage{multienum}

\begin{document}

\begin{multienumerate}
    \mitemxxx{%
        \begin{tikztree}[baseline]
        \Tree[.{} ];
        \end{tikztree}
        }{%
        \begin{tikztree}[baseline]
        \Tree[.{} [.{} ] ];
        \end{tikztree}
        }{%
        \begin{tikztree}[baseline]
        \Tree[.{} [.{} ] [.{} ] ];
        \end{tikztree}
        }
    \vskip\baselineskip
    \mitemxxx{%
        \begin{tikztree}[baseline]
        \Tree[.{} [.{} [.{} ] [.{} ] ] [.{} ] ];
        \end{tikztree}
        }{%
        \begin{tikztree}[baseline]
        \Tree[.{} [.{} [.{} ] ] ];
        \end{tikztree}
        }{%
        \begin{tikztree}[baseline]
        \Tree[.{} [.{} [.{} ] [.{} ] ] ];
        \end{tikztree}
        }
\end{multienumerate}
\end{document}
share|improve this answer

The inline lists offered by enumitem package is also a possibility.

Code

\documentclass{article}
\usepackage{tikz-qtree}
\usepackage[inline]{enumitem}

\newenvironment{tikztree}
{
    \tikzpicture[sibling distance=1cm, level distance=1cm, baseline]
    \tikzset{every node/.style={draw, circle, fill=black, inner sep=0pt, minimum size=2mm}}
}{
    \endtikzpicture
}

\begin{document}
All in one line with automatic line break:

\noindent
\begin{enumerate*}[itemjoin=\hfill]
\item \begin{tikztree}\Tree[.{} ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} ] [.{} ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] [.{} ] ] [.{} ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] [.{} ] ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} ] [.{} ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] [.{} ] ] [.{} ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] [.{} ] ] ];\end{tikztree}
\end{enumerate*}

\vskip30pt
Break into two lines:

\noindent
\begin{enumerate*}[itemjoin=\hfill]
\item \begin{tikztree}\Tree[.{} ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} ] [.{} ] ];\end{tikztree}
\end{enumerate*}
\\ \bigskip
\begin{enumerate*}[itemjoin=\hfill,resume]
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] [.{} ] ] [.{} ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] ] ];\end{tikztree}
\item \begin{tikztree}\Tree[.{} [.{} [.{} ] [.{} ] ] ];\end{tikztree}
\end{enumerate*}

\end{document}

Output

enter image description here

share|improve this answer

The tasks package (which is part of the exsheets package) is what I use in similar situations.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage{tikz-qtree}
\usepackage{tasks}

\newenvironment{tikztree}
{
\tikzpicture[sibling distance=1cm, level distance=1cm, baseline]
\tikzstyle{every node}=[draw, circle, fill=black, inner sep=0pt, minimum size=2mm]
}{
\endtikzpicture
}

\begin{document}

\begin{tasks}[after-item-skip = 5ex, counter-format = tsk. ](3)
    \task \begin{tikztree}\Tree[.{} ];\end{tikztree}
    \task \begin{tikztree}\Tree[.{} [.{} ] ];\end{tikztree}
    \task \begin{tikztree}\Tree[.{} [.{} ] [.{} ] ];\end{tikztree}
    \task \begin{tikztree}\Tree[.{} [.{} [.{} ] [.{} ] ] [.{} ] ];\end{tikztree}
    \task \begin{tikztree}\Tree[.{} [.{} [.{} ] ] ];\end{tikztree}
    \task \begin{tikztree}\Tree[.{} [.{} [.{} ] [.{} ] ] ];\end{tikztree}
\end{tasks}

\end{document}

trees in tasks enviroment

(Also, since you put baseline in your environment definition, you don't need it for each tree.)

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.