14

What is the correct way to label and captionize a tkizpicture inside a tabular environment? (Since figures are not allowed inside a tabular)

Excerpt from my .tex:

\begin{tabular}{l r}

&
   \begin{tikzpicture}
   ... % I want to label this tikzpicutre and give it a nice caption
   \end{tikzpicture}
\end{tabular}

Outside the tabular I would have done it like this:

   \begin{figure}
   \begin{tikzpicture}
   ... 
   \end{tikzpicture}
   \label{fig:...}\caption{...}
   \end{figure}

Basically I want to create a page that looks like this:

----------------------------
|Text Text    TKIZ    TKIZ |
|TextText     TKIZ    TKIZ |
| Text Text   Figure X: ...|
|                          |
|This text is under the    |
|table and references above|
|TKIZ Figure with \ref{..} |
----------------------------
1
  • The "correct" way depends on a lot of factors, including what else is in the tabular (and perhaps why a tabular is needed in the first place). Can you explain your exact problem a little more?
    – ESultanik
    Dec 2, 2010 at 21:55

1 Answer 1

14

I recommend to use the \captionof command of the caption package (or load the tiny capt-of package instead). This command produces captions within other environments than figure or table and even lists them in the list of figures resp. tables.

Here's a complete example for demonstration:

\documentclass{article}
\usepackage{tikz}
\usepackage{caption}
\begin{document}
\listoffigures
\bigskip
\section*{Test table}
\begin{tabular}{lp{4cm}}
Text text text &
   \begin{tikzpicture}
     \draw (0,0) -> (4,0);
   \end{tikzpicture}
   \captionof{figure}{Sample picture}
   \label{tikz}
\end{tabular}

See fig. \ref{tikz}.
\end{document}

alt text

Btw. use \label after \caption, unlike in the example in your question.

4
  • 2
    Since v3.04, the KOMA-Script-classes also provide the \captionof command.
    – lockstep
    Dec 3, 2010 at 0:18
  • +1 for the tip "put \label after \caption", saved my day!
    – qed
    Nov 18, 2013 at 8:50
  • Super good answer, since it does not need figure to be used.
    – gsamaras
    Apr 17, 2015 at 0:41
  • This is working great for me, with one exception. I was sometimes getting a page break inserted between the figure and the caption. I wrapped it in "absolutelynopagebreak" from tex.stackexchange.com/a/94702 . Apr 1, 2016 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .