# Number line and hatching

How to draw number line and hatching with TikZ like the following?

• A try (i.e., some code) from yourself would have been good. – Svend Tveskæg Nov 5 '13 at 13:25

Just for typing exercise with PSTricks. Without simplification, it contains 487 characters.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(-4,-.5)(7.5,1)
\psset{arrows=->}
\pstGeonode[PointName={-3,-2,4,6},PosAngle=-90](-3,0){A}(-2,0){B}(4,0){C}(6,0){D}
\uput{1.2}[0](D){$x$}
\ncline[nodesep=-1]{A}{D}
\psline(A)(A|0,1)([nodesep=-1,offset=1]A)
\psframe[fillstyle=hlines](C)(D|0,.5)
\psline{o-o}(B)(B|0,.5)(D|0,.5)(D)
\psline(C)(C|0,1)([nodesep=3,offset=1]C)
\end{pspicture}
\end{document}


To get bigger dots and arrows, replace the \psset{arrows=->} with \psset{arrows=->,dotscale=2,arrowscale=2}. So the output becomes as follows.

• I don't know why there is all this fuss about the number of characters. The OP has got two solutions by typing only 66 characters. A clear winner. – Mark Wibrow Nov 5 '13 at 15:34
• @MarkWibrow: It is just an additional constraint to be more challenging. IMHO, the fewer keystrokes we use in the code, the more challenging the problem becomes. – kiss my armpit Nov 5 '13 at 15:44

Simpliest tikz solution:

\documentclass[varwidth,border=3pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}
\fill[even odd rule,pattern=north east lines,pattern color=black!30] (4, 0) rectangle (6, 1);
\draw[->] (-4, 0) -- (8, 0);
\draw (-2, 0) |- (4, 1) -| (6, 0);
\draw[->] (4, 0) |- (7, 2);
\draw[->] (-3, 0) |- (-4, 2);
\draw[fill=black] (-3, 0) circle (1mm) node[below] {$-3$};
\draw[fill=white] (-2, 0) circle (1mm) node[below] {$-2$};
\draw[fill=black] (4, 0) circle (1mm) node[below] {$4$};
\draw[fill=white] (6, 0) circle (1mm) node[below] {$6$};
\end{tikzpicture}
\end{document}


• You need border=3pt (approximately) to avoid getting a cropped output. – kiss my armpit Nov 5 '13 at 12:46
• By the way, it contains 636 characters. – kiss my armpit Nov 5 '13 at 13:00
• You can use [-latex] instead of [->] for better arrow. – ferahfeza Nov 5 '13 at 16:27