I'm trying to compile the exact same code suggested in the answer to How to Label and Caption TikzpictureS inside a tabular environment:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{caption/.style={insert path={
let \p1=($(current bounding box.east)-(current bounding box.west)$) in
(current bounding box.south) node[below,text width=\x1-4pt,align=center]
{\captionof{figure}{#1}}}}}
\usepackage{caption}
\begin{document}
\listoffigures
\bigskip
\section*{Test table}
\begin{tabular}{p{4cm}p{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 figs.~\ref{tikz1} and \ref{tikz2}.
\bigskip
\begin{tabular}{cc}
\begin{tikzpicture}
\draw red -> (4,0);
\path[caption={Picture 3.\label{tikz3}}]; % <-- error at this line
\end{tikzpicture}
&
\begin{tikzpicture}
\draw (0,0) -> (4,0);
\path[caption={Picture 4.\label{tikz4}}]; % <-- error at this line
\end{tikzpicture}
\end{tabular}
See figs.~\ref{tikz3} and \ref{tikz4}.
\end{document}
But I end up with ! Package tikz Error: Giving up on this path. Did you forget a semicolon?. at \path[caption={Picture 3.\label{tikz3}}];. I'm sure I already compiled successfully this code (and others using the same technique for adding the caption to a tikzpicture) a while back. The only thing I can think of is that newer versions of tikz (3.1.9a) or caption (3.6b) package are not compatible with this solution...
Also the similar solution suggested by user194703 in Tikzpicture with caption causes the same problem.
Any suggestion would be appreciated!