
我用 pgfplots 創建了一個 groupplot。為了引用每個圖,我在每個圖中的節點內新增了一個子標題。
\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 2}]
\nextgroupplot
\node [text width=1em,anchor=north west] at (rel axis cs: 0,1) {\captionof{subfigure}{\label{fig:a}}};
\addplot plot coordinates {(0,0) (1,1) (2,2) (3,3)};
\nextgroupplot
\node [text width=1em,anchor=north west] at (rel axis cs: 0,1) {\captionof{subfigure}{\label{fig:b}}};
\addplot plot coordinates {(0,0) (1,1) (2,4) (3,9)};
\end{groupplot}
\end{tikzpicture}
\caption{Figure}
\end{figure}
Figure \ref{fig:a} and \ref{fig:b}?!?
\end{document}
問題是:計數器錯誤。子圖 1a 被引用為 0a。我的整個文件中的行為相同,例如 4b 得到 3b。
答案1
使用\subcaption{\label{fig:a}}
和\subcaption{\label{fig:b}}
設定子標題。
代碼:
\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}% <- added, current version is 1.13
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{figure}[htb]
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 2}]
\nextgroupplot
\node [text width=1em,anchor=north west] at (rel axis cs: 0,1)
{\subcaption{\label{fig:a}}};%<- changed
\addplot plot coordinates {(0,0) (1,1) (2,2) (3,3)};
\nextgroupplot
\node [text width=1em,anchor=north west] at (rel axis cs: 0,1)
{\subcaption{\label{fig:b}}};%<- changed
\addplot plot coordinates {(0,0) (1,1) (2,4) (3,9)};
\end{groupplot}
\end{tikzpicture}
\caption{Figure}
\end{figure}
Figure \ref{fig:a} and \ref{fig:b}?!?
\end{document}
請注意,設定一個值很有用compat
。