7

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

\documentclass{article}
\usepackage{tikz}

\definecolor{particle}{rgb}{1.0,0.7,0.3}

\begin{document}

\begin{figure}[h]
   \centering
   \begin{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);
   \end{tikzpicture}
   \caption{Motion in one dimension} \label{fig:tbh1}
\end{figure}

\end{document}

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.

6
  • 3
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – jub0bs
    Commented Aug 10, 2014 at 18:32
  • 1
    I don't get an error with your code! It works as it should
    – cgnieder
    Commented Aug 10, 2014 at 18:40
  • 1
    @Jubobs: Thanks for the warm welcoming! I've edited the code to be compilable. Commented Aug 10, 2014 at 18:40
  • 1
    Hi welcome indeed. There shouldn't be a problem with the given code. Do you have another setting that is named particle somewhere?
    – percusse
    Commented Aug 10, 2014 at 18:41
  • 2
    Not relevant to the issue, but your x-axis labels should be in math mode, particularly as you've otherwise got - appearing as a hyphen not a minus sign.
    – Joseph Wright
    Commented Aug 10, 2014 at 18:55

1 Answer 1

6

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

\usepackage[turkish]{babel}

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

\usetikzlibrary{babel}

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

2
  • Do you kind explaining us how to update PGF/TikZ?
    – bkarpuz
    Commented Sep 1, 2017 at 13:10
  • I was looking for the same problem, that I faced in overleaf. After I saw turkish+babel line, I remembered that I experienced the same problem when I used tikz package for the first time. Is this problem is spesific to turkish language or about babel package, or whatever? Commented Jan 30, 2023 at 12:45

You must log in to answer this question.

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