在我的 tex 文件的 TikZ 代码中,我有一行
\path[draw=cyan] (\xOne+\xTwo+\xThree,2*\yOne+\yTwo+\yThree) ellipse (\xThree and \yOne);
这在编译过程中会触发以下错误:
Package PGF Math Error : Unknown operator 'a' or 'an' (in '28.4527ptand 56.90549pt')
因此,似乎在\xThree
扩展时,以下and
关键字被错误地附加到它上面。添加更多空格并不能解决问题。我该如何解决这个问题?
完整文件如下:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\newdimen\myUnit
\setlength{\myUnit}{1cm}
\begin{document}
\begin{tikzpicture}
\pgfmathsetlengthmacro{\xOne}{\myUnit}%
\pgfmathsetlengthmacro{\xTwo}{2*\myUnit}%
\pgfmathsetlengthmacro{\xThree}{\myUnit}%
\pgfmathsetlengthmacro{\yOne}{2*\myUnit}%
\pgfmathsetlengthmacro{\yTwo}{\myUnit}%
\pgfmathsetlengthmacro{\yThree}{\myUnit}%
\useasboundingbox (0,0) (2*\xOne+2*\xTwo+2*\xThree,\yOne+\yTwo+\yThree);
\path[draw=cyan] (0,0)
-- ++(\xOne,\yOne)
-- ++(\xTwo,\yTwo)
-- ++(\xThree,-\yThree)
-- ++(\xThree,\yThree)
-- ++(\xTwo,-\yTwo)
-- ++(\xOne,-\yOne)
-- cycle
;
\path[draw=cyan] (\xOne+\xTwo+\xThree,2*\yOne+\yTwo+\yThree) ellipse (\xThree and \yOne);
\end{tikzpicture}
Normal text here
\end{document}
答案1
TikZ 解析器要求and
关键字前有一个空格,但LaTeX
会删除宏后的空格。尝试使用更明确的语法:
\path[draw=cyan] ellipse [x radius=\xThree, y radius=\yOne];
尽管你可以使用稍微丑一点的:
\path[draw=cyan] ellipse ({\xThree} and \yOne);