0

I am trying to prepare a slideshow to illustrate the countability of the set of all integers. Here is what I have done so far:

\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}

What I exactly want can be seen with the behaviour of the '0' ball in slide 2. I want to replicate this behaviour for the other balls. Precisely, what I want to add more in each slide from the 3rd slide onwards are

  1. Colour the integer balls in black along the 'Z' line and leave their integer numbering at their centres,
  2. Number the consecutive balls along the 'N' line with their corresponding integer numbering.

I am unable to achieve this with the single variable \n. Is there any way to declare variables based on the even or odd nature of \n? Please help.

1 Answer 1

2

The conditionals are treated in the section 94.2 of the PGFmanual. The syntax is x ? y : z, that is a shorthand for: if x then y else z. Another syntax is ifthenelse(x,y,z).

Here a possible solution of the 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}

Z is countable

1
  • Thank you so much. Beautiful solution! May 15, 2021 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.