! 软件包 PGF 数学错误:未知运算符 `=' 或 `=1'

! 软件包 PGF 数学错误:未知运算符 `=' 或 `=1'

minimum width我正在尝试使用一个命令来计算在定义tikz 的上下文中的天数node

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{datenumber}

\begin{document}

\begin{tikzpicture}%
    \newcounter{startdate}
    \newcounter{enddate}

    \newcommand{\dayssincetimelinestart}[3]{%
          \setmydatenumber{startdate}{1900}{01}{01}%
          \setmydatenumber{enddate}{#1}{#2}{#3}%
          \addtocounter{enddate}{-\thestartdate}%
          \theenddate%
    }

    \node[minimum width=\dayssincetimelinestart{2011}{01}{01}] at (0,0){\dayssincetimelinestart{2011}{01}{01}};

\end{tikzpicture}

\end{document}

计算有效,因为输出显示:

在此处输入图片描述

但是,尝试使用该计算minimum width会产生如下两个错误:

! Package PGF Math Error: Unknown operator `=' or `=1' (in '\@nom =1900\relax \
@den =100\relax \divide \@nom by \@den \multiply \@nom by \@den \@den =1900\adv
ance \@den by -\@nom \@nom =1900\relax \@den =4\relax \divide \@nom by \@den \m
ultiply \@nom by \@den \@den =1900\advance \@den by -\@nom \@tempcnta =28 \gdef
 {}\@tempcntb = 31\relax \global \c@@dayscnt 0\relax \relax \@tempcnta =1800\de
f \iterate {\@nom =\@tempcnta \relax \@den =100\relax \divide \@nom by \@den \m
ultiply \@nom by \@den \@den =\@tempcnta \advance \@den by -\@nom \@nom =\@temp
cnta \relax \@den =4\relax \divide \@nom by \@den \multiply \@nom by \@den \@de
n =\@tempcnta \advance \@den by -\@nom \global \advance \c@@dayscnt 365\relax \
advance \@tempcnta by 1 \relax \iterate }\iterate \let \iterate \relax \global 
\advance \c@@dayscnt 0\relax \@nom =1900\relax \@den =100\relax \divide \@nom b
y \@den \multiply \@nom by \@den \@den =1900\advance \@den by -\@nom \@nom =190
0\relax \@den =4\relax \divide \@nom by \@den \multiply \@nom by \@den \@den =1
900\advance \@den by -\@nom \global \advance \c@@dayscnt 01\relax \global \c@st
artdate 77067\relax \@nom =2011\relax \@den =100\relax \divide \@nom by \@den \
multiply \@nom by \@den \@den =2011\advance \@den by -\@nom \@nom =2011\relax \
@den =4\relax \divide \@nom by \@den \multiply \@nom by \@den \@den =2011\advan
ce \@den by -\@nom \@tempcnta =28 \gdef {}\@tempcntb = 31\relax \global \c@@day
scnt 0\relax \relax \@tempcnta =1800\def \iterate {\@nom =\@tempcnta \relax \@d
en =100\relax \divide \@nom by \@den \multiply \@nom by \@den \@den =\@tempcnta
 \advance \@den by -\@nom \@nom =\@tempcnta \relax \@den =4\relax \divide \@nom
 by \@den \multiply \@nom by \@den \@den =\@tempcnta \advance \@den by -\@nom \
global \advance \c@@dayscnt 365\relax \advance \@tempcnta by 1 \relax \iterate 
}\iterate \let \iterate \relax \global \advance \c@@dayscnt 0\relax \@nom =2011
\relax \@den =100\relax \divide \@nom by \@den \multiply \@nom by \@den \@den =
2011\advance \@den by -\@nom \@nom =2011\relax \@den =4\relax \divide \@nom by 
\@den \multiply \@nom by \@den \@den =2011\advance \@den by -\@nom \global \adv
ance \c@@dayscnt 01\relax \global \c@enddate 77067\relax \global \advance \c@en
ddate -36525\relax 40542').

如何在分配给的表达式中使用该命令minimum width

答案1

您需要执行不可扩展的命令\node选项中。至少\addtocounter是其中之一,因为它的定义来自latex.ltx

\def\addtocounter#1#2{%
  \@ifundefined{c@#1}%
    {\@nocounterr{#1}}%
    {\global\advance\csname c@#1\endcsname #2\relax}}

并且\advance是 TeX 赋值(此处在寄存器上工作\count)。因此,为了解决这个问题,您可以执行以下操作:

\documentclass{article}
\usepackage{tikz}
\usepackage{datenumber}

\newcounter{startdate}
\newcounter{nbdays}

\newcommand*{\dayssincetimelinestart}[3]{%
  \setmydatenumber{startdate}{1900}{01}{01}%
  \setmydatenumber{nbdays}{#1}{#2}{#3}%
  \addtocounter{nbdays}{-\thestartdate}%
  %\thenbdays % commented out: just compute, don't print
}

\begin{document}

\begin{tikzpicture}
  % Compute a new value for the 'nbdays' counter (this does non-expandable things)
  \dayssincetimelinestart{2011}{01}{01}
  % Then use it (\thenbdays is fully expandable -> no problem)
  \node[draw, minimum width=60*\thenbdays sp] at (0,0) { \thenbdays };
\end{tikzpicture}

\end{document}

截屏

我使用了缩放因子60和单位sp,因为结果40542或您的计算不能用作以点为单位的 TeX 长度度量(\maxdimen为 16383.99998pt)。如果我假设您希望以单位表示长度sp,那么它将表示 0.618621pt(40542 除以 65536)并且根本不可见,因为节点内容大于该值。60 在某种程度上是一个任意因子,但在这里给出了宏观(可见)和合理的输出。:-)

如果这不是您想要的,请说出您想要使用哪个单位来得出计算数字的长度。

相关内容