Referenzieren Sie das Gruppendiagramm von pgfplots mit Untertiteln

Referenzieren Sie das Gruppendiagramm von pgfplots mit Untertiteln

Ich habe mit pgfplots ein Gruppendiagramm erstellt. Um jedes Diagramm zu referenzieren, habe ich in jedem Diagramm eine Unterüberschrift innerhalb eines Knotens hinzugefügt.

\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}

Das Problem ist: Der Zähler ist falsch. Die Teilfigur 1a wird als 0a referenziert. Dasselbe Verhalten in meinem gesamten Dokument, z. B. wird 4b als 3b referenziert.

Falsche Verweise auf Untertitel.

Antwort1

Verwenden Sie \subcaption{\label{fig:a}}und , \subcaption{\label{fig:b}}um die Untertitel festzulegen.

Bildbeschreibung hier eingeben

Code:

\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}

Beachten Sie, dass es sinnvoll ist, einen Wert festzulegen compat.

verwandte Informationen