[Tex/LaTex] Common baseline in TikZ and Mathmode

math-modetikz-pgf

Possible Duplicate:
How to align a series of TikZ pictures at the baseline

I want to mix my formulas with some TikZ graphics. For example:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{equation}
  n\cdot
  \tikz[baseline]\node [minimum height=2em,draw=black] {$m$}; \cdot
  \tikz[baseline]\node [draw=black] {a}; \cdot
  b
\end{equation}
\end{document}

This generates the following output:

Latex Output

However, the baseline from Tikz doesn't fit with that from the equation. You see, the m is deeper than the n and the dot is anywhere above it.

How can I make all the text on one common baseline?

Best Answer

The baseline for the box is the bottom of the box. The default behavior is to align to the baseline:

\tikz \node [minimum height=2em,draw=black] {$m$};

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{equation}
  n\cdot
  \tikz \node [minimum height=2em,draw=black] {$m$}; \cdot
  \tikz \node [draw=black] {a}; \cdot
  b
\end{equation}
\end{document}

If you want to align the text at the baseline, then as per Jake's suggetsion you need to add anchor=base:

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{equation}
  n\cdot
  \tikz [anchor=base, baseline] \node [minimum height=2em,draw=black] {$m$}; \cdot
  \tikz [anchor=base, baseline] \node [draw=black] {a}; \cdot
  b
\end{equation}
\end{document}