使用新命令时出现“尺寸太大”

使用新命令时出现“尺寸太大”

当我尝试使用新命令时,tikz我收到多个错误(但都与同一问题有关),显示以下消息“尺寸太大”。我不明白为什么会这样,代码对我来说似乎没问题。我会发布它并解释几点:

\documentclass[]{article}
\usepackage[a4paper, margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{xparse,expl3}

\usetikzlibrary{fit, arrows,backgrounds,patterns,shapes,shapes.multipart,positioning,calc,decorations.markings}
\pgfplotsset{compat=1.7}
\pagestyle{empty}

\tikzset{
    opera/.style={rectangle, align=center, text width=4cm, fill=white},
    datum/.style={font=\scriptsize, rotate=-90},
}

\newcommand*{\evento}[4][]{
        \coordinate (A) at (0,{(#1-1600)/10});
        \coordinate (B) at ({#2},{#3});%
        \node[right=of B, datum] (C) {#1};
        \node[right= of C] (D) {#4};
}


\begin{document}

    \footnotesize

    \begin{tikzpicture}[x=1cm,y=-7mm]
            \centering
       %draw horizontal line   
       \draw[|->, -latex, draw] (0,0) -- (0,39);
       \draw[-, dashed] (0,-0.5) -- (0,0);
       \draw[|->, -latex, draw] (34,0) -- (34,39);
       \draw[-, dashed] (34,-0.5) -- (34,39);

       %draw years
    \foreach \y [evaluate=\y as \year using int(1600+\y*10)] in {0,1,...,38}{ 
        \draw (0,\y) node[left=2pt,anchor=east,xshift=0,font=\scriptsize] {$\year$}; 
        \draw (-0.1,\y) -- (0.1,\y);                
        }

    \foreach \y [evaluate=\y as \year using int(1600+\y*10)] in {0,1,...,37}{ 
        \draw (0,\y) node[left=2pt,anchor=east,xshift=0,font=\scriptsize] {}; 
        \draw (0,\y+.5) -- (0.1,\y+.5);     
        }

        % 1     
        \evento{1653}{5}{2}{The Protectorate began under the Lord Protector Oliver Cromwell};

        % 2     
        % \draw (0, 5.3) edge[out=0,in=180,-*] (5,2) node[datum] {1653} node[opera]{The Protectorate began under the Lord Protector Oliver Cromwell};

    \end{tikzpicture}
\end{document}

我试图制作的实际代码标有1, 号码2但是“手动”版本太长,而且要为每个事件进行修复,这很繁琐,我喜欢最少的代码。New 命令中的代码难道不应该工作并为要使用的两个点提供正确的坐标吗?

如果我写了1653,代码(0, {(#1-1600)/10}))应该会带来(0,5.3),这正是我想要的。

答案1

\evento宏接受四个参数,其中第一个是可选的。

\newcommand*{\evento}[4][]{

文本The Protectorate …甚至不是参数,\evento但不会像伪造的文本那样显示在文档中,;因为 TikZ 安装了一个“nullfont”来阻止这种情况。相反,您会在日志中收到一些警告消息:

Missing character: There is no T in font nullfont!
Missing character: There is no h in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no P in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no t in font nullfont!
[…]
Missing character: There is no w in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no l in font nullfont!
Missing character: There is no ; in font nullfont!

参数#1将为空(使用默认值)。 #2将是1653

只需删除第二个可选参数\newcommand

\newcommand*{\evento}[4]{

相关内容