TikZ Labeled Intervals – Drawing Patterns with TikZ

tikz-pgf

I am trying to draw a diagram using TikZ in which I can specify particular elements within the interval that satisfy a certain condition. This example seems to be the "closest" to what I intend to draw. I tried to modify it, however, due to my limited skills in TikZ, I wasn't able to specify the pattern of labeling, and to draw the interval end braces properly. Any suggestions or hints shall be appreciated.

Intervals Diagram

Best Answer

Here's a try.

Update: Changing the value of \bound will change the maximum number of points on each side of N. Changing the value of the x key will change the distance between adjacent points. (Thanks to @Jubobs for fueling this change)

Code

\documentclass[border=2pt]{standalone}
\usepackage{tikz,amssymb}
\usetikzlibrary{calc}

\newcommand\bound{10} % bound number of points on each side of N
\newcommand\labelnum[3][]{
\begin{scope}[font=\footnotesize,x=.3cm,#1]
  \foreach \mypt in {0,#2,...,\bound}{
    \draw(\mypt,0)circle[radius=2pt];
    \draw(-\mypt,0)circle[radius=2pt];
  }
  \draw(-\bound-5,0)--(\bound+5,0) node[pos=0,left]{$\mathbb Z$};
  \node(start)[at={(-\bound-4,0)},label=below:{$N-d$}]{$[$};
  \node(end)[at={(\bound+4,0)},label=below:{$N+d$}]{$]$};
  \node[at={($(start)!.5!(end)$)},label=below:{$N$}]{\vphantom{$[$}};
  \filldraw(0,0)circle[radius=2pt];
  \node[at={(-\bound-2,0)},above]{$\cdots$};
  \node[at={(\bound+2,0)},above]{$\cdots$};
  \node[at={(0,0)},above=5pt]{#3};
\end{scope}
}

\begin{document}
\begin{tikzpicture}
  \labelnum{1}{All integers are labeled}
  \labelnum[yshift=-2cm]{2}{Even numbers are labeled}
  \labelnum[yshift=-4cm]{5}{Multiples of 5 are labeled}
  \labelnum[yshift=-6cm]{3}{Multiples of 3 are labeled}
\end{tikzpicture}
\end{document}

Output

enter image description here