# tikz picture inside of an enumerate environment

Is there a way I can make sure that the number of the enumerate environment stays in the top left of the tikzpicture? I'm using a custom environment that just wraps around the enumerate environment...

\documentclass{article}
\usepackage{tikz}
\usepackage{enumitem}

\usetikzlibrary{positioning}
\tikzstyle{dot} = [draw=black, fill=white, circle, inner sep=2pt]

\newenvironment{parts}
{\begin{enumerate}[label=\alph*)]}
{\end{enumerate}}

\begin{document}
\begin{parts}
\item
\begin{tikzpicture}
\node (a) {a};
\node (b) [above=1cm of a] {b};
\node (c) [right=1cm of a] {c};
\node (d) [above=1cm of c] {d};
\path
(a) edge node {} (b)
(a) edge node {} (d)
(d) edge node {} (c);
\end{tikzpicture}
\end{parts}
\end{document}
-
have you seen Aligning enumerate labels to top of image?? also, you can change the definition of your parts environment by simply using newlist instead – cmhughes Feb 25 '13 at 3:21
please let us know if your question is different- if the link I provided resolves the issue, that's great, and we'll close this as a duplicate :) – cmhughes Feb 25 '13 at 3:28

The number of the enumerate environment does not move to the bottom, the bottom of the bounding box of the TikZ picture is set at the base line.

This base line can be changed by using the baseline option of TikZ. The PGF manual states in subsection 12.2.1 “Creating a Picture Using an Environment” on page 117.:

The following key influences the baseline of the resulting picture:

tikz/baseline=<dimension or coordinate or default (default 0pt)

Normally, the lower end of the picture is put on the baseline of the surrounding text. For example, when you give the code \tikz\draw(0,0)circle(.5ex);, PGF will find out that the lower end of the picture is at -.5ex and that the upper end is at .5ex. Then, the lower end will be put on the baseline […].

Using this option, you can specify that the picture should be raised or lowered such that the height <dimension> is on the baseline. […]

This options is often useful for “inlined” graphics […].

Instead of a <dimension> you can also provide a coordinate in parentheses. Then the effect is to put the baseline on the y-coordinate that the give[n] <coordinate> has at the end of the picture. This means that, at the end of the picture, the <coordinate> is evaluated and then the baseline is set to the y -coordinate of the resulting point. This makes it easy to reference the y-coordinate of, say, the base line of nodes.

Use the baseline option and you can align the TikZ picture according to the baseline of one of the containing nodes (here: b or d).

\begin{tikzpicture}[baseline=(b.base)]

A general solution would be to use the the top most point of the TikZ picture minus 1em which aligned the top most point at the top of the current line, which incidentally works great for standard rectangular nodes like b or d in your example.

\begin{tikzpicture}[baseline={([yshift=-1em] current bounding box.north)}]

In the following code I have replaced \tikzstyle by \tikzset and added the styles

• enum,
• no enum, and
• base at.

I also changed the parts definition slightly so that every TikZ picture in it is automatically aligned according to the enum style.

See the examples in the code and the output how this effects the outcome and how you can change it for particular TikZ pictures.

## Code

\documentclass{article}
\usepackage{tikz}
\usepackage{enumitem}

\usetikzlibrary{positioning}
\tikzset{
dot/.style={draw=black, fill=white, circle, inner sep=2pt},
enum/.style={baseline={([yshift=-1em] current bounding box.north)}},
base at/.style={baseline={(#1.base)}},
no enum/.style={baseline=default},
}

\newenvironment{parts}
{\tikzset{every picture/.append style={enum}}\begin{enumerate}[label=\alph*)]}
{\end{enumerate}}

\begin{document}
\begin{parts}
\item
\begin{tikzpicture}
\node (a) {a};
\node (b) [above=1cm of a] {b};
\node (c) [right=1cm of a] {c};
\node (d) [above=1cm of c] {d};
\path (a) edge (b)
edge (d)
(d) edge (c);
\end{tikzpicture}
\item \tikz[no enum] \draw (0,0) circle (.5ex);
\item \tikz          \draw (0,0) circle (.5ex);
\item \tikz[base at=a] \node[circle,draw] (a) {X};
\item \tikz            \node[circle,draw] (a) {X};
\end{parts}
\end{document}

-