Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw a very simple number line, i found some code that got me started here. I have modified the code to get the following picture

enter image description here

The problem is that I want the numbers below the line to show up as {-3,2,1,0,1,2,3} but I can't figure out how to modify the following code to do this.

\usetikzlibrary{arrows}
\begin{tikzpicture}
\draw[latex-] (-6.5,0) -- (6.5,0) ;
\draw[-latex] (-6.5,0) -- (6.5,0) ;
\foreach \x in  {-6,-4,-2,0,2,4,6}
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {-6,-4,-2,0,2,4,6}
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] 
{$\x$};
\draw[*-o] (0.92,0) -- (2.08,0);
\draw[very thick    ] (0.92,0) -- (1.92,0);

\end{tikzpicture}

It would nice if I could just divide \x by 2 in place of node[below] {$\x$}, but I don't know how to do this. Thanks!

share|improve this question
    
Change {-6,-4,-2,0,2,4,6} to {-3,-2,-1,0,1,2,3} –  azetina Dec 3 '13 at 23:20
    
I didn't mean to write \x2= int(mod(\x +2,3)) in the middle of the code. I deleted it now. –  JimmyJackson Dec 3 '13 at 23:31
2  
Similar visualization: [1]; different visualization: [2], [3]. –  Qrrbrbirlbel Dec 3 '13 at 23:39
    
@Qrrbrbirlbel Thanks This is helpful. –  JimmyJackson Dec 3 '13 at 23:46
2  
You can use $\pgfmathprint{int(\x/2)}$ as node text. By the way, why don't you put the node part in the first loop and remove the second one entirely? If you want to follow @azetina's comment, you can use {-3,...,3} but with x=2cm or xscale=2. –  Qrrbrbirlbel Dec 3 '13 at 23:49

2 Answers 2

up vote 3 down vote accepted

See the following MWE:

enter image description here

\documentclass[letterpaper]{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\draw[latex-latex] (-3.5,0) -- (3.5,0) ; %edit here for the axis
\foreach \x in  {-3,-2,-1,0,1,2,3} % edit here for the vertical lines
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {-3,-2,-1,0,1,2,3} % edit here for the numbers
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] 
{$\x$};
\draw[*-o] (0.92,0) -- (2.08,0);
\draw[very thick] (0.92,0) -- (1.92,0);
\end{tikzpicture}
\end{document}

Here is something that can work for now with the scaling:

\begin{tikzpicture}[scale=2.5]
\draw[very thick] (1,0) -- (2,0);
\path [draw=black, fill=black] (1,0) circle (2pt);
\path [draw=black, fill=white, thick] (2,0.0) circle (2pt);
\draw[latex-latex] (-3.5,0) -- (3.5,0) ;
\foreach \x in  {-3,-2,-1,0,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {-3,-2,-1,0,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] 
{$\x$};
\end{tikzpicture}
share|improve this answer
    
How about if I want to make more space between each number? –  JimmyJackson Dec 3 '13 at 23:27
    
@JimmyJackson Well the way you have defined the intervals on the number line will look weird if you make it bigger. –  azetina Dec 3 '13 at 23:36
    
The scaling worked well thanks! –  JimmyJackson Dec 3 '13 at 23:54
    
scale will scale everything including small circle and ticks ;) –  Harish Kumar Dec 3 '13 at 23:55
    
@HarishKumar Yeah I know, I warned the OP about it. –  azetina Dec 3 '13 at 23:56
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot}
\psset{xunit=15mm}
\begin{document}
\begin{pspicture}(-3,-.5)(3,.5)
    \psaxes[yAxis=false,ticksize=0 -4pt]{<->}(0,0)(-3,-1)(3,1)
    \psline[linecolor=blue,arrowscale=1.25]{o-*}(.5,0)(2,0)
\end{pspicture}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.