我想在循环中绘制点。给出了 x 和 y 坐标(两个变量)。我认为这在语法上是正确的,但 tikz 却不是这样。有人能帮忙吗?
母语:
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{% for turning direction of an arrow tip, man p203
}
\usepackage[paperheight=160mm,
paperwidth=180mm,
top=5mm,
bottom=5mm,
left=5mm,
right=5mm,
]{geometry}
\tikzset{%
inner sep=0pt,%
outer sep=2pt,%
mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=00pt,}%mark=x}%
}
\begin{document}
\begin{tikzpicture}
% All Points
let \c={0};
\foreach \px/\py in {%
0/4,
1.9/5.92,
1.9/5.363,
0.56/4.0,%
}{%
let \c={\c+1};
\coordinate[mark coordinate,] (p\c) at (\px,\py);
\node[rotate=45,label={[left]{\tiny p\c}}] at (p\c) {\tiny{+}};
}
\end{tikzpicture}
\end{document}
答案1
这是常见的问题:\foreach
按组执行每个循环,因此let\c=\c+1
一旦该组结束,您就会被遗忘。
您可以改用count=\c
(/pgf/foreach/count
,手册第 1005 页)。
\documentclass[]{article}
\usepackage{tikz}
\tikzset{
inner sep=0pt,
outer sep=2pt,
mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=0pt,}
}
\begin{document}
\begin{tikzpicture}
% All Points
\foreach \px/\py [count=\c] in {%
0/4,
1.9/5.92,
1.9/5.363,
0.56/4.0
}{%
\coordinate[mark coordinate,] (p\c) at (\px,\py);
\node[label={[left]{\tiny p\c}}] at (p\c) {\tiny$\times$};
}
\end{tikzpicture}
\end{document}
使用$\times$
比旋转 + 更好。