我正在尝试准备一个幻灯片来说明所有整数集的可数性。以下是我目前所做的工作:
\documentclass[aspectratio=169]{beamer}
\usetheme{CambridgeUS}
\usefonttheme{serif}
\setbeamercolor{background canvas}{bg=black}
\setbeamercolor{normal text}{fg=white}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{frame}{$ \mathbb{Z} $ is countable}
\begin{figure}
\centering
\begin{tikzpicture}[>=stealth, font=\tiny, declare function={a=0.2;b=2;c=6.5;}]
\onslide<+->
{
\foreach \n in {-10,...,-1}
\fill [blue] (\n/2,0) node[white] {$ \n $} circle (a);
\foreach \n in {1,...,10}
\fill [magenta] (\n/2,0) node[white] {\n} circle (a);
\fill [magenta!50!blue] (0,0) node[white] {0} circle (a);
\node [left=-5pt] at (-5.5,0) {\huge$ \dots $};
\node [right=-5pt] at (5.5,0) {\huge$ \dots $};
\node at (0,-0.5) {\normalsize$ \mathbb{Z} $};
\draw [thick, ->] (-1/2+a,-0.5) -- (-6.5,-0.5);
\draw [thick, ->] (1/2-a,-0.5) -- (6.5,-0.5);
\draw [thick, ->] (1/2-a-c-0.5,-b-0.75) -- (21/2-c,-b-0.75);
\node at (-c-0.5,-b-0.75) {\normalsize$ \mathbb{N} $};
\foreach \n in {1,...,21}
{
\draw [densely dotted] ({(\n-1)/2-c},-b) circle (a);
\node at ({(\n-1)/2-c},-b-0.5) {\footnotesize$ \n $};
}
\node [right=-5pt] at (21/2-c,-b-0.5) {\huge$ \dots $};
\node [right=-5pt] at (21/2-c,-b) {\huge$ \dots $};
}
\onslide<+->
{
\fill [magenta!50!blue] (-c,-b) node[white] {0} circle (a);
\fill [black] (0,0) node[white] {0} circle (a);
}
\foreach [evaluate=\n as \tint using {(1+(-1)^\n)*50}] \n in {1,...,20}
{
\onslide<+->
{
\fill [blue!\tint!magenta] (\n/2-c,-b) circle (a);
}
}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
我真正想要的可以从幻灯片 2 中的“0”球的行为中看出。我想为其他球复制这种行为。确切地说,我想从第 3 张幻灯片开始在每张幻灯片中添加更多内容
- 沿着“Z”线将整数球涂成黑色,并在其中心保留整数编号,
- 用相应的整数编号对“N”线上的连续球进行编号。
我无法使用单个变量来实现这一点\n
。有没有办法根据偶数或奇数性质声明变量\n
?请帮忙。
答案1
条件句在 PGFmanual 的第 94.2 节中进行了处理。语法是,即 if then elsex ? y : z
的简写。另一种语法是。x
y
z
ifthenelse(x,y,z)
这是 OP 的一个可能的解决方案:
\documentclass[aspectratio=169]{beamer}
\usetheme{CambridgeUS}
\usefonttheme{serif}
\setbeamercolor{background canvas}{bg=black}
\setbeamercolor{normal text}{fg=white}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{frame}{$ \mathbb{Z} $ is countable}
\begin{figure}
\centering
\begin{tikzpicture}[>=stealth, font=\tiny, declare function={a=0.2;b=2;c=6.5;}]
\onslide<+->
{
\foreach \n in {-10,...,-1}
\fill [blue] (\n/2,0) node[white] {$ \n $} circle (a);
\foreach \n in {1,...,10}
\fill [magenta] (\n/2,0) node[white] {\n} circle (a);
\fill [magenta!50!blue] (0,0) node[white] {0} circle (a);
\node [left=-5pt] at (-5.5,0) {\huge$ \dots $};
\node [right=-5pt] at (5.5,0) {\huge$ \dots $};
\node at (0,-0.5) {\normalsize$ \mathbb{Z} $};
\draw [thick, ->] (-1/2+a,-0.5) -- (-6.5,-0.5);
\draw [thick, ->] (1/2-a,-0.5) -- (6.5,-0.5);
\draw [thick, ->] (1/2-a-c-0.5,-b-0.75) -- (21/2-c,-b-0.75);
\node at (-c-0.5,-b-0.75) {\normalsize$ \mathbb{N} $};
\foreach \n in {1,...,21}
{
\draw [densely dotted] ({(\n-1)/2-c},-b) circle (a);
\node at ({(\n-1)/2-c},-b-0.5) {\footnotesize$ \n $};
}
\node [right=-5pt] at (21/2-c,-b-0.5) {\huge$ \dots $};
\node [right=-5pt] at (21/2-c,-b) {\huge$ \dots $};
}
\onslide<+->
{
\fill [magenta!50!blue] (-c,-b) node[white] {0} circle (a);
\fill [black] (0,0) node[white] {0} circle (a);
}
\foreach [evaluate=\n as \zn using {iseven(\n)?int(-(\n+1)/2):int((\n/2)+1)},
evaluate=\n as \colzn using {iseven(\n)?"blue":"magenta"}] \n in {1,...,20}
{
\onslide<+->
{
\fill [\colzn] (\n/2-c,-b) circle (a) node[white]{$\zn$};
\fill [black] (\zn/2,0) node[white] {$\zn$} circle (a);
}
}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}