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?
Asked
Active
Viewed 414 times
2
Mazzy
- 7,642
2 Answers
2
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}

Gonzalo Medina
- 505,128
-
1
minipagemay be better thancenter, as that prohibits a pagebreak between figure and caption. – Torbjørn T. Nov 22 '12 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? – Nax Apr 22 '14 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 '14 at 13:08
-
2
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.
Count Zero
- 17,424
figureenvironment? – Count Zero Nov 22 '12 at 15:29\begin{figure}\begin{tikzpicture}...\end{tikzpicture}\caption{whatever}\label{fig:my_fav_tikz}\end{figure}. That should do the trick.:)– Count Zero Nov 22 '12 at 15:32figureenvironment; 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