Getting a tikz picture to have an equation number

I make a lot of commutative diagrams and am trying to switch to Tikz from amcd,diagrams, etc. I often have to refer to these diagrams in the text and would rather have them as equations (i.e. with and equation number) rather than a figure. I have tried just putting it in an equation environment but it neither centers the diagram (as ma)

• Please explain more why putting them as figures is no good. Presumably because you want to refer to commutative diagrams as if they were equations? Buy why can't you just refer to figures instead? Commented Oct 20, 2010 at 12:21
• @Seamus: In a math paper, commutative diagrams are functionally like equations, so the coherent thing is to label both in the same way. In a math paper, in which one customarily refers to dozens, if not hundreds, of equations, writing "Figure 32" instead of (32) is cumbersome. Also the label "Figure 32" takes up more (vertical) space than does a margin equation number. Surely there are still other reasons, but those are what occur to me. Commented Sep 10, 2013 at 16:32

$$\begin{tikzpicture}[baseline=(current bounding box.center)] ...... \end{tikzpicture}$$


Copied from Mtikz.pdf.

• That's really slick---the [baseline=(current bounding box.center)] centers the equation reference number, rather than having it at the bottom of the picture. Commented Oct 20, 2010 at 18:02
• Exactly. "equation" puts the reference number on the baseline of the picture, so the solution is to move the baseline. Commented Oct 20, 2010 at 18:55
• And it works for all sorts of other things, too, like labelling for lists! that's great---thanks! Commented Oct 20, 2010 at 19:59
• Could the example about be edited to include \hbox, then the answer would be complete? Commented Oct 21, 2010 at 8:53
• I don't understand your comment --- there is no need for \hbox. Did you even try it? Commented Oct 21, 2010 at 13:39

just place the TikZ picture into a box, for example using \text{} (which is an AMS command).

In case you do not use AMS, you can also use \hbox (which is a plain TeX command) instead.

Example which compiles without extra packages:

$$\hbox{\tikz\draw[draw=black,fill=red] (0,0) circle (5pt);} \label{eq:test}$$

\noindent
In (\ref{eq:test}), we see a TikZ picture.\dotfill


Christian

• This is still using a distinct counter from the one used in the equation environment, so this might not work how the OP wanted it to... Commented Oct 20, 2010 at 13:16
• @Seamus: How is the counter distinct? @user1537: \eqref handles the parentheses.
– TH.
Commented Oct 20, 2010 at 13:51
• Thanks , hbox works for generating an appropriate equation number, but I am using the tikzpicture environment, which seems to conflict with \text{} which for some reason it doesnt like and the equation number is not placed correctly (at the bottom of the diagram rather than the middle). Commented Oct 20, 2010 at 14:17
• @user1536: Use \vcenter instead of \hbox.
– TH.
Commented Oct 20, 2010 at 15:21
• @TH Sorry, I didn't notice that you'd wrapped the hbox in an equation environment, I thought hbox had its own counter, that was distinct. I see now what you mean... Commented Oct 20, 2010 at 16:26

If your Tikz image lives inside a standalone file, Mephisto's answer will not work since baseline modifications do not carry over to the main document, unfortunately.

Another option that will work in such cases is to wrap the Tikz image in amsmath's aligned environment.

\begin{aligned} \includestandalone{<tikzimage>} \end{aligned}


If this is used frequently (as OP states) one should consider wrapping this construction inside a custom environment.

\newenvironment{alignedeqn}
{\begin{aligned}} {\end{aligned}\ignorespacesafterend}


To put the equation number on top or bottom (which is the default) just use the following commands:

$$\begin{tikzpicture}[baseline=(current bounding box.north)] .... \end{tikzpicture}$$


or

$$\begin{tikzpicture}[baseline=(current bounding box.south)] .... \end{tikzpicture}$$


which is the default.

• what if I want the equation number to be in the middle? Commented Aug 18, 2022 at 9:48
• Nevermind box.east, did the job haha ;) Thanks anyway! Commented Aug 18, 2022 at 9:49