# How to color numbers in axis?

I want to color the numbers 3 in blue and -1 in green as show in the picture below.

My code is this :

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-4.5,xmax=4,xstep=1]
\tkzAxeX[label={}]
\coordinate (A) at (3,0);
\coordinate (O) at (0,0);
\coordinate (B) at (-1,0);
\coordinate (C) at (.5,.7);
\coordinate (D) at (4,.7);
\coordinate (E) at (-.5,.7);
\coordinate (F) at (-4,.7);
\tkzDrawSegment[ultra thick, color=blue](O,A)
\tkzDrawSegment[ultra thick, color=green](O,B)
\tkzDrawSegments[dashed](O,C C,D O,E E,F)
\end{tikzpicture}
\end{document}


I use the tkz-euclide package

-
Can you make the code into a minimal working example (MWE)? –  egreg May 18 '13 at 10:33
I don't know how to change the color of only a few numbers defined with \tkzInit, but a temporary (i.e. not really proper) solution would be adding nodes like \node[color=blue] at (3,-.34) {3};. –  Ailurus May 18 '13 at 11:30
It's not possible with \tkzAxeXbecause this macro is used to get general result. The best solution is to place the numbers with tikz manually. –  Alain Matthes May 18 '13 at 11:54
Another possibility is to write a new macro ... –  Alain Matthes May 18 '13 at 12:52

First remark. The tkz collection is created to do some automatic pictures with general options. If you want to create specific pictures with a flexible method, I think it's better to learn Tikz and to use it.

Manually, you need to use \tkzDrawX[label={}] instead of \tkzAxeX. The solution is possible because in your code you have xstep=1 and you use a lot default options. Another method is to overwrite some nodes with color and fill=white (if the background is white)

 \documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-4.5,xmax=4]
\tkzDrawX[label={}]
\coordinate (A) at (3,0);
\coordinate (O) at (0,0);
\coordinate (B) at (-1,0);
\coordinate (C) at (.5,.7);
\coordinate (D) at (4,.7);
\coordinate (E) at (-.5,.7);
\coordinate (F) at (-4,.7);
\tkzDrawSegment[ultra thick, color=blue](O,A)
\tkzDrawSegment[ultra thick, color=green](O,B)
\tkzDrawSegments[dashed](O,C C,D O,E E,F)
\node[below,text=green] at (-1,0) {$-1$};
\node[below,text=blue] at (3,0) {$3$};
\foreach \x in {-4,-3,-2,0,1,2,4}  \node[below,] at (\x,0) {$\x$};
\end{tikzpicture}
\end{document}


Second method with default options. It's not very fine but you get the result that you want

 \documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-4.5,xmax=4,xstep=1]
\tkzAxeX[label={}]
\coordinate (A) at (3,0);
\coordinate (O) at (0,0);
\coordinate (B) at (-1,0);
\coordinate (C) at (.5,.7);
\coordinate (D) at (4,.7);
\coordinate (E) at (-.5,.7);
\coordinate (F) at (-4,.7);
\tkzDrawSegment[ultra thick, color=blue](O,A)
\tkzDrawSegment[ultra thick, color=green](O,B)
\tkzDrawSegments[dashed](O,C C,D O,E E,F)
\node[below=2pt,text=blue,fill=white] at (3,0) {$3$};
\end{tikzpicture}
\end{document}

-
I think the first solution is better thanks! –  mac May 19 '13 at 13:58