当我想定义和命名坐标列表时遇到了一个奇怪的错误
\tikz{
\foreach \name/\pos in {{a/(1,0)}, {b/(0,1)}}
\coordinate (\name) at \pos ;
}
错误是
{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] [2] [3]
Runaway argument?
\pos ;\pgffor@endhook \ifx \pgffor@assign@after@code \pgfutil@empty \ETC.
! Paragraph ended before \tikz@@coordinate@@at was complete.
<to be read again>
\par
l.44
列表的手动扩展有效。我也可以使用以下语法来使用 foreach,但我觉得这不太自然
\tikz{
\foreach \name/\pos in {{a/(1,0)}, {b/(0,1)}}
\draw \pos node (\name) {\name};
\draw (a)--(b);
}
带有交换变量的完整示例也不起作用。
\documentclass[tikz,border=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usetikzlibrary{scopes, arrows, decorations.markings, calc, intersections}
\begin{document}
\begin{tikzpicture}
\foreach \pos/\name in {{(1,0)}/a, {(0,1)}/b}
\coordinate (\name) at \pos;
\draw (a)--(b);
\end{tikzpicture}
\end{document}