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


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)



\newcommand\bound{10} % bound number of points on each side of N
  \foreach \mypt in {0,#2,...,\bound}{
  \draw(-\bound-5,0)--(\bound+5,0) node[pos=0,left]{$\mathbb Z$};

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


enter image description here

  • You shoudn't have so many "magical numbers". – jub0bs Jan 22 '14 at 23:45
  • @Jubobs: I've made an update. Does it look better now? :) – Herr K. Jan 23 '14 at 0:03
  • I shall now bestow a +1 on you :). – jub0bs Jan 23 '14 at 0:17
  • Thank you. This certainly matches what I wanted to draw. Is there an easy way to add the labels, e.g., "Multiples of 3 are labeled"? – Abdullah Heyari Jan 23 '14 at 13:49
  • 1
    @AbdullahHeyari: See updated answer. I modified \labelnum to take an extra argument, which sets the "title" of the line. – Herr K. Jan 23 '14 at 17:30

A PSTricks solution where the diagram has been 'automated'; one can now choose all the absolute and relative distances in the diagram and it will automatically change accordingly.




  \cs_new_eq:NN \calc \fp_eval:n
% values needed (automatically calculated)
\newcommand*\StartDist{\calc{\Beginning+\StartIndent} }

%%% parameters %%%
% endpoints of axes
\newcommand*\Beginning{2 }
\newcommand*\End{12 }
% distance between axes
% constants of indentation on axes
% number of big, `hollow' dots on the lines


{\psset{dotstyle = Bo}
\multido{\rC = \StartDots+\DistDots{\DotsLineTop}}{\DotsLineTop}{\psdot(\rC,\HeightAxis{3})}
\uput[90](\Middle,\HeightAxis{3}){\scriptsize Even numbers are labeled}
\multido{\rB = \StartDots+\DistDots{\DotsLineMiddle}}{\DotsLineMiddle}{\psdot(\rB,\HeightAxis{2})}
\uput[90](\Middle,\HeightAxis{2}){\scriptsize Multiples of $3$ are labeled}
\multido{\rA = \StartDots+\DistDots{\DotsLineBottom}}{\DotsLineBottom}{\psdot(\rA,\HeightAxis{1})}
\uput[90](\Middle,\HeightAxis{1}){\scriptsize Multiples of $5$ are labeled}}
\multido{\r = 0.35+\AxesDist}{3}{%
  \multido{\rD = \SmallDotsStart+\SmallDotsDist, \rE = \SmallDotsEnd+\SmallDotsDist}{3}{%
   {\psset{dotsize = 2pt}
    \psdot(!\rD\space \r\space 0.1 add)
    \psdot(!\rE\space \r\space 0.1 add)}}
  \uput[270](\StartDist,\r){\scriptsize $N-d$}
  \uput[270](\Middle,\r){\scriptsize $N$}
  \uput[270](!\Beginning \End add \StartDist sub \r){\scriptsize $N+d$}
  \rput(!\Beginning \End add \StartDist sub \r\space 0.1 add){$]$}
  \rput(!\StartDist \r\space 0.1 add){$[$}}



  • 1
    Thank you. Your suggested answer introduced me to the power of PSTricks! – Abdullah Heyari Jan 23 '14 at 13:51
  • @AbdullahHeyari Glad I could help. :) (Remember to accept one of the answers in due time.) – Svend Tveskæg Jan 23 '14 at 13:59
  • I shall select an answer soon. Something is hindering the proper execution of the PSTricks on my computer. I received multiple error messages saying: Undefined control sequence \multido – Abdullah Heyari Jan 23 '14 at 15:49
  • @AbdullahHeyari Have you got an updated LaTeX distribution? If not, try to update it. – Svend Tveskæg Jan 23 '14 at 16:00

Another solution with PSTricks just for spending the boring time.


    \foreach \y/\t in {0/{Even numbers },-4/{Multiples of 3 },-8/{Multiples of 5 }} 
        \uput[90](0,\y){\t are labeled}
        \pscircle*[linecolor=red](!\i\space dup 2 mod 0 ne {/SD {} def} if 0){2pt}
        \pscircle*[linecolor=green](!\i\space dup 3 mod 0 ne {/SD {} def} if -4){2pt}
        \pscircle*[linecolor=blue](!\i\space dup 5 mod 0 ne {/SD {} def} if -8){2pt}

enter image description here

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.