我正在尝试编译与以下答案中建议的完全相同的代码如何在表格环境中标记和标题 TikzpictureS:
\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](0,0) -> (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}
但我最终得到了! Package tikz Error: Giving up on this path. Did you forget a semicolon?.
。\path[caption={Picture 3.\label{tikz3}}];
我确信我已经成功编译了这段代码(以及其他使用相同技术将标题添加到 tikzpicture 的代码)。我唯一能想到的是,较新版本的tikz
(3.1.9a) 或caption
(3.6b) 包与此解决方案不兼容……此外,user194703 建议的类似解决方案带标题的 Tikzpicture导致同样的问题。
任何建议都将不胜感激!
答案1
\captionof
在组中使用总是最安全的(通常来自minipage
或类似的环境)。包中的更改caption
意味着现在需要一个组。
\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}}}}}}% extra {}
\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](0,0) -> (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}
运行无错误。
我不知道这是否是有意为之的改变,也许值得向caption
软件包作者提出。