----------------------------------------------------------------------
In illo tempore...
----------------------------------------------------------------------
Blog | Projects | Tags

TikZ: an integer number line

cohen-precalc-1.1B.png

TikZ does the math for you - tell it you want to put something at \((\sqrt{2}+\sqrt{3}, 0)\) and it will calculate the exact location.

\#+begin_src latex :file ./img/cohen-precalc-1.1B.png :imagemagick yes :results output silent :fit yes :imoutoptions -geometry 900 :iminoptions -density 600
\begin{tikzpicture}[
  >=Stealth,
  define rgb/.code={\definecolor{mycolor}{RGB}{#1}},
  rgb color/.style={define rgb={#1},mycolor}
]
  % x-axis
  \draw[<->] (-5,0) -- (5,0);

% 11
  \fill[black] (11/4,0) circle (0.4 mm) node[above=6pt] {\scriptsize\strut $11/4$};
  \draw (11/4,0) -- ++(0,7pt);

% 12
  \fill[black] (-7/8,0) circle (0.4 mm) node[above=6pt] {\scriptsize\strut $-7/8$};
  \draw (-7/8,0) -- ++(0,7pt);

% 13
  \fill[black] ({sqrt(2) + 1},0) circle (0.4 mm) node[above=20pt] {\scriptsize\strut $1+\sqrt{2}$};
  \draw ({sqrt(2) + 1},0) -- ++(0,22pt);

% 14
  \fill[black] ({1-sqrt(2)},0) circle (0.4 mm) node[above=20pt] {\scriptsize\strut $1-\sqrt{2}\quad$};
  \draw ({1-sqrt(2)},0) -- ++(0,22pt);

% 15
  \fill[black] ({sqrt(2)-1},0) circle (0.4 mm) node[above=20pt] {\scriptsize\strut $\quad\sqrt{2}-1$};
  \draw ({sqrt(2)-1},0) -- ++(0,22pt);

% 16
  \fill[black] ({-sqrt(2)-1},0) circle (0.4 mm) node[above=20pt] {\scriptsize\strut $-\sqrt{2}-1$};
  \draw ({-sqrt(2)-1},0) -- ++(0,22pt);

% 17
  \fill[black] ({sqrt(2)+sqrt(3)},0) circle (0.4 mm) node[above=32pt] {\scriptsize\strut $\sqrt{2}+\sqrt{3}$};
  \draw ({sqrt(2)+sqrt(3)},0) -- ++(0,34pt);

% 18
  \fill[black] ({sqrt(2)-sqrt(3)},0) circle (0.4 mm) node[below=20pt] {\scriptsize\strut $\sqrt{2}-\sqrt{3}$};
  \draw ({sqrt(2)-sqrt(3)},0) -- ++(0,-22pt);

% 19
  \fill[black] ({(1+sqrt(2))/2},0) circle (0.4 mm) node[below=20pt] {\scriptsize\strut $(1+\sqrt{2})/2$};
  \draw ({(1+sqrt(2))/2},0) -- ++(0,-22pt);

% 20
  \fill[black] ({(2*sqrt(3)+1)/2},0) circle (0.4 mm) node[below=32pt] {\scriptsize\strut $(2\sqrt{3}+1)/2$};
  \draw ({(2*sqrt(3)+1)/2},0) -- ++(0,-34pt);

  % labeled dots in Cohen Precalculus 4ed blue
  \foreach \i in {-4,-3,...,4} % points on line
    \fill
      [rgb color={0,165,214}]
      (\i,0)
      circle (0.8 mm)
      node[below=6pt,black] {$\i$};

\end{tikzpicture}

Bill White (billw@wolfram.com) ยท Emacs 30.0.50 (Org mode 9.6.11)