我想为LaTeX中的变量分配一个值范围,以在tikzpicture环境中的循环中使用。
在下面的代码中,我想替换这些行
\begin{tikzpicture}
\foreach \x in {1, 3, 5, 7}
\foreach \y in {2, ..., 5}{
用类似的东西
first_range = {1, 3, 5, 7}
second_range = {2, ..., 5}
\begin{tikzpicture}
\foreach \x in first_range
\foreach \y in second_range{
完整的可运行代码部分如下:
\documentclass{article}
\usepackage{tikz}
\usepackage{ifthen}
\begin{document}
\begin{tikzpicture}
\foreach \x in {1, 3, 5, 7}
\foreach \y in {2, ..., 5}{
\ifthenelse{\(\x=1 \OR \x=7\) \AND \y = 3}{
%\filldraw[fill=white] (\x, \y) circle (0.2);
\node[] at (\x, \y) {\vdots};
}{
\filldraw[fill=red] (\x, \y) circle (0.2);
}
}
\end{tikzpicture}
\end{document}
您可以将列表存储在宏中:
\documentclass{article}
\usepackage{tikz}
\usepackage{ifthen}
\def\first{1, 3, 5, 7}
\def\second{2, ..., 5}
\begin{document}
\begin{tikzpicture}
\foreach \x in \first
\foreach \y in \second {
\ifthenelse{\(\x=1 \OR \x=7\) \AND \y = 3}{
%\filldraw[fill=white] (\x, \y) circle (0.2);
\node[] at (\x, \y) {\vdots};
}{
\filldraw[fill=red] (\x, \y) circle (0.2);
}
}
\end{tikzpicture}
\end{document}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句