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've drawn a tree using pgf/tikz and am trying to place it in an enumerated list. A snippet of my complete code is as follows:

\subsection*{Problem 2}
\begin{enumerate}[1)]
\item Max heap
\item
\begin{tikzpicture}[level/.style={sibling distance=50mm/#1}]
\node [circle,draw] (z){98}
  child {node [circle,draw] (a) {80}
    child {node [circle,draw] (b) {23}
      child {node [circle,draw] (c) {18}}
      child {node [circle,draw] (d) {21}}
    }
    child {node [circle,draw] (g) {48}}
  }
  child {node [circle,draw] (j) {79}
    child {node [circle,draw] (k) {76}}
    child {node [circle,draw] (l) {29}}
};
\end{tikzpicture}
\end{enumerate}

My problem is the list number is aligned with the bottom of the tikzpicture. How would I go about aligning it with the top of the tikzpicture?

share|improve this question
2  
A complete (compilable) minimal example would be better. For example until now it's not clear which of the packages enumerate and enumitem has been used. –  Stefan Kottwitz Nov 6 '10 at 22:12

4 Answers 4

up vote 7 down vote accepted

Here is one way:

\item \leavevmode\vadjust{\vspace{-\baselineskip}}\newline
\begin{tikzpicture}
share|improve this answer
2  
+1 for this answer since, if anything else, it's a perfectly useful and acceptable solution for all parts of the question posed at tex.stackexchange.com/questions/5413/… (for which I also answered, only in a rather different way, and for which I really wish I'd seen your answer here first -- it would have saved me very much time :) ). –  Geoffrey Jones Nov 16 '10 at 15:37
2  
The problem with this is that the number can wind up on a separate page from the tree. Matthew's solution solves that. –  emily Dec 28 '12 at 21:42

Just add baseline:

\begin{tikzpicture}[level/.style={sibling distance=50mm/#1},baseline]

without any arguments, baseline takes the value 0pt, which is great because your tree grows downwards. So y=0 is at the top.

share|improve this answer
1  
+1 for the conceivably simplest solution. –  Thorsten Donig Nov 7 '10 at 10:03

You have to determine explicitly the base line of the tikzpicture environment with respect to the current line. See sample below.

\documentclass{article}
\usepackage{tikz}

\begin{document}
  \begin{enumerate}
    \item Max heap
    \item
      \begin{tikzpicture}[%
        baseline=(current bounding box.north),
        level/.style={sibling distance=50mm/#1}
      ]
        \node [circle,draw] (z){98}
        child {node [circle,draw] (a) {80}
          child {node [circle,draw] (b) {23}
            child {node [circle,draw] (c) {18}}
            child {node [circle,draw] (d) {21}}
          }
          child {node [circle,draw] (g) {48}}
        }
        child {node [circle,draw] (j) {79}
          child {node [circle,draw] (k) {76}}
            child {node [circle,draw] (l) {29}}
        };
      \end{tikzpicture}
  \end{enumerate}
\end{document}
share|improve this answer
    
Even better is baseline={($(current bounding box.north)-(0,1.6ex)$)} as it aligns the top of the picture with the top of the line. (Don’t forget to add \usetikzlibrary{calc}.) –  Caramdir Nov 6 '10 at 22:15

A simple way to bring the number up (and this is what I always do) is to simply add ~\\ after \item.

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.