I've often need to write out equations between pictures, which are drawn using TikZ. However, to display them properly, I have two requirements: any common features must be on the same horizontal line, and the diagrams as a whole must be vertically centered with respect to any = signs separating them.
Here's a picture of the effect I want:
Here's a picture of the effect I don't want, but which is easily achieved:
Of course, for a particular diagram, it's just a couple of lines of code to get the effect I want. But ideally, I'd specify the position of the labels - perhaps by setting the baseline of the diagrams to the label A - and then the rest should happen automatically.
There are many ways I can achieve this manually: for example, increasing the size of the bounding box for the smaller diagram to artificially force it to have the same height as the larger one; or manually setting the baseline of the images to exactly the point which I want aligned with the baseline of the = sign. But both of these are fiddly, and none are robust against future changes of the diagrams.
Here's the code to produce the second image above:
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\[
\begin{aligned}
\begin{tikzpicture}
\draw (0,0)
node [above] {$A$}
to [out=down, in=down] (1,0)
node [above] {$A^*$};
\end{tikzpicture}
\end{aligned}
=
\begin{aligned}
\begin{tikzpicture}
\draw (0,0)
node [above] {$A$}
to [out=down, in=up] (1,-1)
to [out=down, in=down] (0,-1)
to [out=up, in=down] (1,0)
node [above] {$A^*$};
\end{tikzpicture}
\end{aligned}
\]
\end{document}