0

I'm attempting to reference a figure containing a tikzpicture from pgfplots. However, for some reason, I'm getting ?? instead of the figure number when I \ref it.

Any ideas what I'm doing wrong?

The section is below:

\subsection{Graph of Results}
Figure \ref{fig:ResultsGraph} shows the data gathered in Table \ref{tbl:ResultsData}.
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[legend pos=north east,anchor=west, xlabel={$\dfrac{1}{T} / K^{-1}$}, ylabel={$ln P*_a$}]
\addplot table [only marks, x=1/T,y=lnPa]{GraphData.txt};
\addplot [thick, red] table[y={create col/linear regression={y=lnPa}}]{GraphData.txt};
\addlegendentry{$\dfrac{dy}{dx} = \pgfplotstableregressiona$}
\addlegendentry{$y_{intercept} = \pgfplotstableregressionb$}
\end{axis}
\label{fig:ResultsGraph}
\end{tikzpicture}
\caption{Graph to show the relationship between the natural log of pressure and the inverse of temperature}
\end{figure}
1
  • 4
    \label should appear after \caption - see here.
    – greyshade
    Commented Oct 23, 2017 at 11:06

1 Answer 1

2

As greyshade said, the \label should appear after the \caption.

You may have put \label inside the tikzpicture environment with the intuition that the picture itself is what you're labeling and referring to. But from LaTeX's point of view, what you're labeling and referring to is the figure's caption. So putting \label outside the tikzpicture environment, between the \caption and the \end{figure}, will do what you need.

1
  • 1
    Strictly speaking, you're referring to the \caption, not the figure environment. There can be more than one \caption in the same figure. Commented Oct 23, 2017 at 14:19

Not the answer you're looking for? Browse other questions tagged .