In pgfplots, when I use a custom style to plot a line, \label the line and then \ref to this plot, I am unable to get the desired result.
The desired result would be to get a little line where I am using \ref.
The actual result:
- On the first compilation, I get
LaTeX Warning: Reference 'plot:coor' on page 1 undefined on input line 11., and the line in the text gets replaced by??. - The second compilation fails with
! Package pgfkeys Error: I do not know the key '/tikz/custom' and I am going to ignore it. Perhaps you misspelled it..
I'm using:
pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)LaTeX2e <2011/06/27>pgfplots 2011/07/29 v1.5 (git show 1.5-1-gcc2f2d2 )tikz 2010/10/13 v2.10 (rcs-revision 1.76).
A minimum (not) working example:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[custom/.style={thick}]
\begin{axis}
\addplot[custom] coordinates {(0,0) (1,1) (2,3)};
\label{plot:coor}
\end{axis}
\end{tikzpicture}
This is \ref{plot:coor}.
\end{document}
If I add the custom style to the axis-environment, the problem remains. If I copy the thick to the arguments of addplot, the problem goes away. However, in my real situation, I apply a similar style to four different plots, so I would like to use a custom style. My questions:
- Is this a bug?
- If yes, is it known and is there a workaround?
- If no, how do I
\refer to a\labeled plot created with a custom style? - Why is it behaving in this way?
Related but different questions:
- pgfplots, custom legend and tikz library external
- In an answer to Using \ref in a ylabel of a pgfplot a bug is mentioned affecting
pgfplotsand\ref. If I replace\ref{plot:coor}by{\fixcheck \ref{plot:coor}, where\fixcheckis defined as in the aforementioned question, the problem remains.
axisenvironment are local. Note that\pgfplotsset{custom/.style...}will define a key called/pgfplots/custom, while\begin{tikzpicture}[custom/.style...]will create/tikz/custom. This doesn't matter for plot styles, because pgfplots checks both directories, but if you want to use the plot style with other TikZ objects (like\draw [custom] ...), you should use\tikzset{custom/.style.... – Jake Dec 07 '11 at 11:24