31

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? – Seamus Oct 20 '10 at 12:21
  • 3
    @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. – Dan Fox Sep 10 '13 at 16:32
37
\begin{equation}
\begin{tikzpicture}[baseline=(current  bounding  box.center)]
......
\end{tikzpicture}
\end{equation}

Copied from Mtikz.pdf.

  • 2
    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. – Leah Wrenn Berman Oct 20 '10 at 18:02
  • Exactly. "equation" puts the reference number on the baseline of the picture, so the solution is to move the baseline. – Mephisto Oct 20 '10 at 18:55
  • And it works for all sorts of other things, too, like labelling for lists! that's great---thanks! – Leah Wrenn Berman Oct 20 '10 at 19:59
  • Could the example about be edited to include \hbox, then the answer would be complete? – user1536 Oct 21 '10 at 8:53
  • I don't understand your comment --- there is no need for \hbox. Did you even try it? – Mephisto Oct 21 '10 at 13:39
4

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:

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

\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... – Seamus Oct 20 '10 at 13:16
  • 1
    @Seamus: How is the counter distinct? @user1537: \eqref handles the parentheses. – TH. Oct 20 '10 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). – user1536 Oct 20 '10 at 14:17
  • @user1536: Use \vcenter instead of \hbox. – TH. Oct 20 '10 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... – Seamus Oct 20 '10 at 16:26
1

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{equation}
\begin{aligned}
    \includestandalone{<tikzimage>}
\end{aligned}
\end{equation}

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

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

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

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

or

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

which is the default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.