Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm drawing a automaton figure, and I want to name it says 'M1' below the figure? A minimal example would be greatly appreciated. Thank you.

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
    \node[state,initial]    (q_0)                   {$q_0$}; 
    \node[state,accepting]  (q_1)   [right=of q_0]  {$q_1$}; 
    \node[state]            (q_2)   [right=of q_1]  {$q_2$}; 

    \path[->]
    (q_0) edge                  node {a}            (q_1)
    (q_1) edge                  node {$\lambda$}    (q_2)
    (q_2) edge  [bend right]    node {$\lambda$}    (q_0)
    ; %end path 
\end{tikzpicture}
share|improve this question
    
Do you need a real caption like for figures with a running counter or just some text below it? You self-answer lets me goes it's the second case. In the first case should the pictures be labeled on their own, independent from the figures? –  Martin Scharrer Jul 24 '11 at 21:20
    
The text below a picture is what I needed, as provided in my answer. The reason that I used the word caption is because I googled and found that. I thought it was similar to a caption for a picture. There are two pictures being drawn next to each other, so I think the text solution is easier to manage in this particular situation. Nonetheless, I would agree with you on the first solution for a true caption for a picture. –  Chan Jul 24 '11 at 21:24

2 Answers 2

up vote 29 down vote accepted

Just include your code in a figure environment. In that way you'll be able to add a caption to it as a normal figure:

\begin{figure}
\centering
\begin{tikzpicture}
<code>
\end{tikzpicture}
\caption{M1} \label{fig:M1}
\end{figure}
share|improve this answer
    
Thank you for your quick response. However the picture position changes accordingly, it moves to the bottom of the page :(. –  Chan Jul 24 '11 at 20:18
2  
@Chan: Everything with caption should usually be a floating object, i.e. it should be automatically moved to the typographically most sensible position. That is what figure does. If you really don't want a float, then have a look at tex.stackexchange.com/questions/7210/…. –  Caramdir Jul 24 '11 at 20:29
1  
@Caramdir: Thank you. In fact, I've just found a more elegant solution in the TikZ manual by using an extra \node with text. Unfortunately, the compiler was freeze for some reasons. –  Chan Jul 24 '11 at 20:33
4  
If you don't like the position of the figure you can specify it in the optional argument of the figure environment like that: \begin{figure}[t]. Instead of t (top) you can use b (bottom), p (new page of floats) or h (here) or a combination of them. All of these options works well if LaTeX thinks that the result would be typographically correct. –  Spike Jul 25 '11 at 7:22
    
@Spike: Although your comment was posted for a while, I still want to thank you for that. –  Chan Aug 6 '11 at 0:12

This is my solution using an extra node with text, it works pretty well.

\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
        \node[state,initial]    (q_1)                           {$q_1$}; 
        \node[state,accepting]  (q_2)   [right=of q_1]          {$q_2$}; 
        \node[state]            (q_3)   [below right=of q_1]    {$q_3$}; 

        \path[->]
        (q_1) edge  [bend left]     node {a}            (q_2)
        (q_1) edge  [loop above]    node {b}            (q_1)
        (q_2) edge  [bend left]     node {a,b}          (q_3)
        (q_3) edge  [bend left]     node {a}            (q_2)
        (q_3) edge  [bend left]     node {b}            (q_1);

        \node [below=1cm, align=flush center,text width=8cm] at (q_3)
        {
            $M_1$
        };
\end{tikzpicture}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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