[Tex/LaTex] Package pgfkeys Error: The key ‘/tikz/opacity’ requires a value


I'm drawing a diagram for a physical phenomenon, "motion in one dimension". I have this figure with a tikzpicture:




      \draw[help lines] (0,0) grid (8,2);
      \draw[thick] (0,0) -- (8,0);
      \node [right] at (8.25,0) {x (m)};
      \node [below] at (0,0) {-40};
      \node [below] at (1,0) {-30};
      \node [below] at (2,0) {-20};
      \node [below] at (3,0) {-10};
      \node [below] at (4,0) {0};
      \node [below] at (5,0) {10};
      \node [below] at (6,0) {20};
      \node [below] at (7,0) {30};
      \node [below] at (8,0) {40};
      \draw [draw=black, fill=particle, opacity=0.5]
         (1,0) rectangle (2,1);
      \draw [draw=black, fill=particle]
         (6,0) rectangle (7,1);
   \caption{Motion in one dimension} \label{fig:tbh1}


Compiling with pdflatex, I get this error:

! Package pgfkeys Error: The key '/tikz/opacity' requires a value. I am going to ignore this key.

… on this line:

l.73 ...w [draw=black, fill=particle, opacity=0.5]

Didn't I specify a value for the opacity already? Why am I getting this error?

EDIT: Edited the code to be compilable.

Best Answer

Further investigation of the error led to the fact that when the line


was omitted from the preamble, the code compiled just fine. (I didn't put this line into the code in the question, because, I thought it was irrelevant. Another lesson learned.)

To fix the issue, I added the line


to the preamble. It didn't work at first, but when I upgraded PGF/TikZ from 2.10 to 3.00, it did.

Related Question