![程序包 pgfkeys 错误:键 '/tikz/opacity' 需要一个值](https://linux22.com/image/295896/%E7%A8%8B%E5%BA%8F%E5%8C%85%20pgfkeys%20%E9%94%99%E8%AF%AF%EF%BC%9A%E9%94%AE%20'%2Ftikz%2Fopacity'%20%E9%9C%80%E8%A6%81%E4%B8%80%E4%B8%AA%E5%80%BC.png)
我正在绘制一个物理现象“一维运动”的图表。我有figure
这个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}
使用 pdflatex 进行编译时,出现以下错误:
! Package pgfkeys Error: The key '/tikz/opacity' requires a value. I am going to ignore this key.
...在此行:
l.73 ...w [draw=black, fill=particle, opacity=0.5]
我不是已经指定了不透明度的值吗?为什么会出现此错误?
编辑:编辑代码以便可编译。
答案1
对错误进一步调查后发现,当
\usepackage[turkish]{babel}
从序言中省略了,代码编译得很好。(我没有把这行放入问题的代码中,因为我认为它不相关。又学到了教训。)
为了解决这个问题,我添加了一行
\usetikzlibrary{babel}
回到序言。一开始它不起作用,但是当我将 PGF/TikZ 从 2.10 升级到 3.00 时,它就可以工作了。