我正在编写一个简单的脚本来制作随机卡片,用于在课堂上教授统计思想。我使用 Tikz 制作了随机卡片,这些卡片都遵循我想要的布局,使用嵌套的 foreach 循环。然而,我看到了一个我无法追踪的奇怪现象。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,left=0mm,right=0mm,top=0mm,bottom=0mm]{geometry}
\usepackage{graphicx,tikz,pgfmath}
\begin{document}
%Define a vector of dog breeds: breed,breed image,lower random effect level, upper random effect level, and effect level offset
\newcommand{\dogBreeds}{Akita/Akita.png/0/5/5,Beagle/Beagle.png/6/12/0,Collie/Collie.png/28/40/0,Dalmatian/Dalmatian.png/30/45/75}%\newcommand{\dogBreeds}
%Define vectors of values for the (x,y) center of each card
\newcommand{\xCardColumnCenters}{2.5,6}
\newcommand{\yCardRowCenters}{1.5,3.5,5.5,7.5,9.5}
%Define vectors of x values for the Edge of each card
\newcommand{\xCardLeftEdge}{0.75,4.25}
\newcommand{\xCardRightEdge}{4.25,8}
%Define vectors of y values for the Edge of each card
\newcommand{\yCardLowerEdge}{0.5,2.5,4.5,6.5,8.5}
\newcommand{\yCardUpperEdge}{2.5,4.5,6.5,8.5,10.5}
%iterate through the dog breeds
\foreach \breed / \image / \lower / \upper / \offset in \dogBreeds{
\begin{tikzpicture}[remember picture,overlay]
%remember picture, overlay allow us to use absolute measurements on the page, ignoring any margins
%iterate through the y and x columns to build a matrix of cards
\foreach \y in \yCardRowCenters {
\foreach \x in \xCardColumnCenters {
%center and scale the image using (x,y) relative to the page in absolute coordinates
\node[xshift=\x in,yshift=\y in,anchor=center](image) at (current page.south west) {\includegraphics[height=1.5 in]{\image}};
}%\foreach \x in \xCardColumnCenters
}%\foreach \y in \yCardRowCenters
\foreach \x in \xCardRightEdge {
\foreach \y in \yCardRowCenters {
\node[fill=white,xshift=\x in,yshift=\y in,rotate=90,anchor=south] at (current page.south west) {\huge{\textbf{BREED}}};
}%\foreach \y in \yCardRowCenters
}%\foreach \x in \xCardRightEdge {
\foreach \x in \xCardLeftEdge {
\foreach \y in \yCardUpperEdge {
\node[fill=white,xshift=\x in,yshift=\y in,anchor=north west] at (current page.south west) {\Large{\breed}};
}%\foreach \y in \yCardRowCenters
\foreach \y in \yCardLowerEdge {
%create a random effect size
\pgfmathsetmacro{\effect}{random(\lower,\upper)-\offset};
\node[fill=white,xshift=\x in,yshift=\y in,anchor=south west] at (current page.south west) {\Large{Effect: $\effect$}};
}%\foreach \y in \yCardLowerEdge
}%\foreach \y in \yCardRowCenters
\end{tikzpicture}
\clearpage
}%\foreach \breed in \dogBreeds
\end{document}
这会产生所需的输出,但有一个例外。在每个新页面的顶部,它会在每页顶部放置一个数字(\dogBreeds 命令中的第一个数字)。我不确定是什么原因造成的;我尝试在每组条目的开头创建一个数字索引,但这并没有消除这种影响。很奇怪。有什么想法吗?
答案1
将变量名改为 以外的名称\lower
。事实上,始终使用\my<macro>
name 来确保不会与 TeX 原语发生冲突。