I want to use the nice answer to the similar question How to Label and Caption a Tikzpicture inside a tabular environment. The problem is I want two pictures side by side, with a caption for each. I duplicate the MWE to get:
\documentclass{article}
\usepackage{tikz}
\usepackage{caption}
\begin{document}
\listoffigures
\bigskip
\section*{Test table}
\begin{tabular}{lp{4cm}}
\begin{tikzpicture}
\draw [red](0,0) -> (4,0);
\end{tikzpicture}
\captionof{figure}{Picture 1}
\label{tikz1}
&
\begin{tikzpicture}
\draw (0,0) -> (4,0);
\end{tikzpicture}
\captionof{figure}{Picture 2}
\label{tikz2}
\end{tabular}
\
See fig. \ref{tikz1} and \ref{tikz2}.
\end{document}
but this does not compile, the error is
(./captnof.lof) ! You can't use `\hrule' here except with leaders. \caption@hrule ->\hrule @height \z@
l.12 \captionof{figure}{Picture 1}
Once the line
\captionof{figure}{Picture 1}
is commented out, it does. So the
\captionof
works for the right picture but not for the left one! Is there a way around?
