\RequirePackage{environ} % ### DEFINE NumberLine ENVIRONMENT ### % define numberLine/area parameters \pgfkeys{/numberLine/area/.is family, /numberLine/area, height/.estore in = \numberLineAreaHeight, color/.estore in = \numberLineAreaColor, opacity/.estore in = \numberLineAreaOpacity, label/.store in = \numberLineAreaLabel, textcolor/.store in = \numberLineAreaTextcolor, textabove/.store in = \numberLineAreaTextPosition } \pgfkeys{/numberLine/area, default/.style = {height=0.2, color=orange, opacity=1, label=, textcolor=black, textabove=0.2ex}} % define numberLine/area parameters \pgfkeys{/numberLine/point/.is family, /numberLine/point, size/.estore in = \numberLinePointSize, color/.estore in = \numberLinePointColor, textcolor/.store in = \numberLinePointTextcolor, textabove/.store in = \numberLinePointTextPosition } \pgfkeys{/numberLine/point, default/.style = {size=0.1, color=orange, textcolor=black, textabove=0.3ex}} % define environment \NewEnviron{numberLine}[3][]{ % Draw an xtick at (1: x-position, 2: label to display) \newcommand{\xtick}[2]{ \draw (##1,0.1) -- + (0,-0.2) node[below] {$##2$} } % Draw an area on the number-line (1: from x, 2: to x, 3: color) \newcommand{\area}[3][]{ \pgfkeys{/numberLine/area, default, ##1} \begin{pgfonlayer}{areas} \fill [\numberLineAreaColor,fill opacity=\numberLineAreaOpacity] (##2,-0.1) rectangle (##3,{-0.1 + \numberLineAreaHeight}) node[pos=.5,yshift=\numberLineAreaTextPosition,label={[\numberLineAreaTextcolor]\numberLineAreaLabel}] {}; \end{pgfonlayer} } % Draw a point on the number-line (1: x-position, 2: color, 3: size) \newcommand{\point}[3][]{ \pgfkeys{/numberLine/point, default, ##1} \begin{pgfonlayer}{points} \fill[\numberLinePointColor] (##2,0) circle (\numberLinePointSize) node[above=\numberLinePointTextPosition,text=\numberLinePointTextcolor] {##3}; \end{pgfonlayer} } \pgfdeclarelayer{areas} \pgfdeclarelayer{points} \pgfsetlayers{areas,main,points} \begin{tikzpicture}[#1] \BODY %draw horizontal line above everything else (except the x-ticks) \draw (#2,0) -- (#3,0); %draw xticks above everything else \foreach \x in {#2,...,#3} \xtick{\x}{\x}; \end{tikzpicture} }