我一直尝试在子图中标记图像,然后在主图环境的标题中引用它们。但是我收到所有三个子图的错误“标签没有正确引用”和“引用未定义错误”。有人能找出问题所在吗?
\begin{figure}[t]
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img1}
\label{fig:original}
\end{subfigure}
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img2}
\label{fig:smooth}
\end{subfigure}
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img3}
\label{fig:binarySkeleton}
\end{subfigure}
\caption{\ref{fig:original}Image 1 \ref{fig:smooth}image 2 \ref{fig:binarySkeleton} Image 3 }
\label{fig:pre-processing}
\end{figure}
答案1
如果您有包含标签 a、b、c 的图像/图表,并且不需要标题,则可以使用{\phantomsubcaption\label{subfiglabel}}
。例如:
\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\includegraphics[width=0.3\linewidth]{example-image-a}\hfill
\includegraphics[width=0.3\linewidth]{example-image-b}\hfill
\includegraphics[width=0.3\linewidth]{example-image-c}
{\phantomsubcaption\label{first subfig}}
{\phantomsubcaption\label{second subfig}}
{\phantomsubcaption\label{third subfig}}
\caption{...}
\label{full fig}
\end{figure}
See fig.~\ref{full fig}, which contains \ref{first subfig}, \ref{second subfig} and \ref{third subfig}.
\end{document}
答案2
只需添加空标题:
\documentclass[demo]{article}
\usepackage{subcaption, graphicx}
\begin{document}
\begin{figure}[t]
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img1}
\caption{}\label{fig:original}
\end{subfigure}
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img2}
\caption{}\label{fig:smooth}
\end{subfigure}
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img3}
\caption{}\label{fig:binarySkeleton}
\end{subfigure}
\caption{\ref{fig:original} Image 1, \ref{fig:smooth} image 2, \ref{fig:binarySkeleton} Image 3.}%
\label{fig:pre-processing}
\end{figure}
\end{document}