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 created markov's chain using tikz package. Now I would add to to it caption and label but I got error.How can I add a caption and a label to a tikz object?

share|improve this question
1  
Please provide a MWE. The question as you stated it is way to broad to give a meaningful answer. By the way, did you include your TikZ picture in a figure environment? –  Count Zero Nov 22 '12 at 15:29
    
no I didn't include in a figure environment –  Mazzy Nov 22 '12 at 15:30
1  
Then I suggest: \begin{figure}\begin{tikzpicture}...\end{tikzpicture}\caption{whatever}\label{f‌​ig:my_fav_tikz}\end{figure}. That should do the trick. :) –  Count Zero Nov 22 '12 at 15:32
    
Ok now it works...I simply add figure environment –  Mazzy Nov 22 '12 at 15:32
1  
@Mazzy it's not mandatory to use a figure environment; it depends on whether you want the object to float or not. Please see my answer below for more details. –  Gonzalo Medina Nov 22 '12 at 15:41

2 Answers 2

up vote 2 down vote accepted

In case you want to use floating environments, you will need to include the TikZ picture in a figure environment:

\begin{figure}
\begin{tikzpicture}
...% TikZ code goes here
\end{tikzpicture}
\caption{whatever}
\label{f‌​ig:my_fav_tikz}
\end{figure}

If you don't want floats, see Gonzalo Medina's answer.

share|improve this answer
    
Well, my answer also includes the float case. –  Gonzalo Medina Nov 22 '12 at 15:45
    
Ok, I didn't see that... I'll delete my answer. –  Count Zero Nov 22 '12 at 15:57
    
can't delete - been accepted... –  Count Zero Nov 23 '12 at 0:12

If you don't want the object to float, you can use, for example, a minipage and \captionof from the caption package.

If you want the object to be treated as a floating object, you can enclose it within a figure environment.

A simple example illustrating both approaches:

\documentclass{article}
\usepackage{tikz}
\usepackage{caption}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\draw (0,0) circle (1cm);
\end{tikzpicture}
\caption{A tikz circle}
\label{fig:testb}
\end{figure}

\noindent\begin{minipage}{\textwidth}
\centering
\begin{tikzpicture}
\draw (0,0) circle (1cm);
\end{tikzpicture}
\captionof{figure}{A tikz circle}
\label{fig:testa}
\end{minipage}

\end{document}

enter image description here

share|improve this answer
1  
minipage may be better than center, as that prohibits a pagebreak between figure and caption. –  Torbjørn T. Nov 22 '12 at 15:37
    
@TorbjørnT. you're right. Change made. Thanks. –  Gonzalo Medina Nov 22 '12 at 15:39
    
I tried the first way you in your answer, the tikzpicture and the caption are OK, but strangely the picture appear another place, this is to say it does follow orders of the article. So , can you help me Gonzalo? –  Alex Apr 22 at 13:05
    
@Alex Sure, but we need the code, otherwise little help can be provided. Please open a follow-up question and provide there a minimal version of a document (like the one in my answer) illustrating the problem; you can also provide a link to this answer to provide some background. –  Gonzalo Medina Apr 22 at 13:08
    
thX, I know where the problem lies –  Alex Apr 22 at 14:30

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.