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?
2 Answers
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{fig:my_fav_tikz}
\end{figure}
If you don't want floats, see Gonzalo Medina's answer.
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}
-
1
minipage
may be better thancenter
, as that prohibits a pagebreak between figure and caption. Nov 22, 2012 at 15:37 -
-
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?– NaxApr 22, 2014 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. Apr 22, 2014 at 13:08
-
figure
environment?\begin{figure}\begin{tikzpicture}...\end{tikzpicture}\caption{whatever}\label{fig:my_fav_tikz}\end{figure}
. That should do the trick.:)
figure
environment; it depends on whether you want the object to float or not. Please see my answer below for more details.