Skip to main content
4 of 4
edited title
jub0bs
  • 60.3k
  • 25
  • 213
  • 295

Why doesn't TikZ's \foreach iterate over the last element of the list?

This code

\documentclass{report} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[dashed] (1,-1) -- (1,2) node[above] {$1$}; \draw[dashed] (2,-1) -- (2,2) node[above] {$2$}; \foreach \x in {1,1.1,...,2} {\draw[fill = yellow] (\x,1) circle (0.05);} \foreach \x in {1,1.2,...,2} {\draw[fill = red] (\x,0) circle (0.05);} \end{tikzpicture} \end{document} 

produces the following output.

enter image description here

The first \foreach produces the yellow circles. There is no circle at 2, the last element in the set {1,1.1,...,2} over which it iterates.

The second \foreach produces the red circles. There is a circle at 2, the last element in the set {1,1.2,...,2} over which it iterates.

Why do these two commands behave differently?