我正在尝试创建一个宏来计算形状的中心。请考虑以下代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\getcellcent}[4]{
\coordinate (#1) at ($1/3*(V#2)+1/3*(V#3)+1/3*V(#4)$);
}
\begin{document}
\begin{tikzpicture}
\coordinate (V1) at (0,0);
\coordinate (V2) at (2,0);
\coordinate (V3) at (1,1);
\getcellcent{C1}{1}{2}{3}
\draw[black] (V1) -- (V2) -- (V3) -- cycle;
\node[circle,radius=1,fill=red] at (C1) {};
\end{tikzpicture}
\end{document}
在这里我收到以下错误信息:
Runaway argument?
1/3*V(3)$); \draw [black] (V1) -- (V2) -- (V3) -- cycle; \node [circ\ETC.
! File ended while scanning use of \tikz@cc@parse@factor.
如果我将 \getcellcent 改为
\coordinate (C1) at ($1/3*(V1)+1/3*(V2)+1/3*(V3)$);
运行正常。我这里遗漏了什么?
答案1
开头的括号V(#4)
错误,应该在“V”之前