tikz:\coordinate 作为参数

tikz:\coordinate 作为参数

我可以定义并使用\newcommand \Ball

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\newcommand{\Ball}[2]{
  \draw(#1, #2) circle(2 cm);
}
\begin{tikzpicture}
  \Ball{1}{4};
\end{tikzpicture}
\end{document}

输出是一个漂亮的球:

在此处输入图片描述

\coordinate但如果我可以将其作为参数传递给\Ball:那就更好了:

\coordinate(O) at (1, 4);
\Ball -> pass (O) as argument;

类似地,我可以这样写:

\coordinate(O) at (1, 4);
\draw(O) circle(2 cm);  

可以这样做吗?

答案1

您可以将坐标作为普通参数传递。

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}

\newcommand{\Ball}[1]{
  \draw(#1) circle(2cm);
}

\begin{tikzpicture}
  \coordinate (O) at (1, 4);
  \Ball{O};
\end{tikzpicture}

\end{document}

相关内容