以下代码出现此错误:
! Argument of \pgfmathrnd@@ has an extra }.
<inserted text>
\par
l.12 }
?
! Emergency stop.
<inserted text>
\par
l.12 }
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on bob.log.
Done.
怎么了 ?
\documentclass[tikz]{standalone}
\usetikzlibrary{patterns}
\pgfdeclarepatternformonly{Rnd}
{\pgfpointorigin}{\pgfpoint{.5cm}{.5cm}}
{\pgfpoint{1cm}{1cm}}
{
\pgfpathcircle{%
%\pgfpoint{.25cm}{.25cm}}{.4pt}
\pgfpoint{\pgfmathrnd*.25cm}{\pgfmathrnd*.25cm}}{.4pt}
\pgfusepath{fill}
}
\begin{document}
\begin{tikzpicture}
\draw[pattern=Rnd] (0,0) rectangle (5,5) ;
\end{tikzpicture}
\end{document}
答案1
在这种情况下,无法使用宏\pgfmathrnd
,\pgfmathrand
否则\pgfmathrandom
结果将不是适合解析的形式。正确的方法是直接使用函数rnd
,rand
或random
:
\pgfpoint{rnd*.25cm}{rnd*.25cm}}{.4pt}