First time using LaTeX. I read some questions on here but I am still confused.

All I want to do is to draw a simple number line between -3 and 3, and plot some points, say 0.5, 0.7, and 0.9.

How do I do that?


Do you mean something like

            % center the x axis
            axis x line=middle,
            % we don't need a y axis line ...
            axis y line=none,
            % ... and thus there is no need for much `height' of the axis
            % but `height' also changes `width' which is restored here
            \addplot coordinates {
                (0.5,0) (0.7,0) (0.9,0)

image showing the result of above code


A pure tikz alternative:

enter image description here

    \draw (-3,0) -- (3,0);
    \foreach \i in {-3,-2,...,3} % numbers on line
      \draw (\i,0.1) -- + (0,-0.2) node[below] {$\i$}; % tick and their labels
    \foreach \i in {0.5, 0.7, 0.9}% points on line
      \fill[red] (\i,0) circle (0.6 mm);
  • 1
    How about putting the \i inside $ so the minus signs are right? Oct 8 '16 at 19:51
  • 1
    oh, i have filling that i would forget something ... thank you!. corrected now.
    – Zarko
    Oct 8 '16 at 19:54

Here's an adaption of one I made earlier. The code is designed to support various options so not all of it is necessarily to draw the simple line in this case. Additional options have, in fact, been added to turn some of those features off.

This makes the preamble a bit complex, though potentially useful if you like that kind of thing. However, the code for the actual numberline is not especially complex.

  dot=blue,% colour of dots marking points on the line
  dot opacity=.75,% opacity of dots
  fraction=1,% we're only marking whole numbers
  ticks above=false,% we only want standard axis marks below
  min=-3,% start from here - max is 3 by default
  number to=none,% we don't want to visualise a number as drawn along a fraction of the line
  h scale=3,% scale the line a bit as the marks are too close otherwise
  mark at={0.5,0.7,0.9},% points we want to mark on the line


\tikzset{% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
  number line/.code={
      /number line/.cd,%
  /number line/.cd,
  dot/.store in=\nl@dot,
  dot opacity/.store in=\nl@dotopacity,
  fill/.store in=\nl@fill,
  fraction/.store in=\nl@fraction,
  h scale/.store in=\nl@hscale,
  line height/.store in=\nl@lineht,
  line above/.store in=\nl@lineabove,
  line below/.store in=\nl@linebelow,
  mark at/.store in=\nl@markat,
  max/.store in=\nl@max,
  min/.store in=\nl@min,
  mixed numbers/.is if=nl@mixednumbers,
  mixed numbers/.default=true,
  number to/.store in=\nl@numberto,
  number from/.store in=\nl@numberfrom,
  ticks above/.is if=nl@ticksabove,
  ticks above/.default=true,
  v scale/.store in=\nl@vscale,
  v scale=1.2,
  h scale=4,
  number to={7/4},
  number from=0,
  mixed numbers=false,
  dot opacity=.75,
  ticks above,
  mark at=,
  line height=0.2,
  line above=0.2,
  line below=0.2,
\newcommand*\tnl{% modified from ref: WeCanLearnAnything at http://tex.stackexchange.com/questions/267921/macro-for-mixed-numbers-on-number-line-tikz (but I doubt this is the original source)
      \filldraw[\nl@fill] (\nl@numberfrom,0) rectangle (\nl@numberto,\nl@lineht);% shaded portion of number line
    (\nl@min,0)--(\nl@max,0)% lower part of x-axis
    (\nl@min,\nl@lineht)--(\nl@max,\nl@lineht);% higher part of x-axis
    \foreach \x in {\nl@min,...,\nl@max}
      \node [anchor=mid] at (\x,-0.5) {\x};% whole numbers underneath number line
    \foreach \x in {\nl@minfrac,...,\nl@maxfrac}% fractional tick marks and numbers above number line
      \draw (\x/\nl@fraction,-\nl@linebelow)--(\x/\nl@fraction,\nl@lineht);
        \node[above] at (\x/\nl@fraction,{\nl@lineht+0.05}) {$\frac{\x}{\nl@fraction}$}; % draw tick and mark fraction above line
        \pgfmathsetmacro\intbit{int(\x/\nl@fraction)}% integer bit
        \pgfmathsetmacro\fracbit{int(\x-\nl@fraction*\intbit)}% proper fraction bit
        \ifnum\intbit=0\let\intbit\relax\fi % don't print 0 in mixed numbers
          \node [anchor=mid] at (\x/\nl@fraction,{-\nl@linebelow-0.3}) {$\intbit\frac{\fracbit}{\nl@fraction}$}; % mark the mixed number below the line
      \fill[\nl@dot,opacity=\nl@dotopacity] (\nl@numberto,.5*\nl@lineht) circle[x radius=\nl@lineht cm/\nl@hscale,y radius=\nl@lineht cm/\nl@vscale];% dot
    \foreach \i in \nl@markat
      \draw (\i,0) -- (\i,{\nl@lineht+\nl@lineabove}) node [above] {\i};% draw tick to node above line to mark point specified with mark at
      \fill[\nl@dot,opacity=\nl@dotopacity] (\i,.5*\nl@lineht) circle[x radius=\nl@lineht cm/\nl@hscale,y radius=\nl@lineht cm/\nl@vscale];% dot
\NewDocumentCommand \NumberLine { s O {} }{%
  \IfBooleanTF {#1}{%
    \tikz[number line={mixed numbers=false,#2}]\tnl;%
    \tikz[number line={mixed numbers=true,#2}]\tnl;%


  dot opacity=.75,
  ticks above=false,
  number to=none,
  h scale=3,
  mark at={0.5,0.7,0.9},


With a simple picture environment without TikZ:


%\fboxsep=.1pt \fbox{% debug for bounding box
  \put(-3, 0){\line(1, 0){6}}
  \multiput(-3, -.1)(1, 0){7}{\line(0, 1){.2}}
    \put(\x, -.2){\makebox(0, 0)[t]{$\x$}}%
    \put(\x, 0){\circle*{.1}}%
% }% end of \fbox




A PSTricks solution.

Same colored dots



\def\Dot(#1){\psdot[dotstyle = o, fillcolor = blue](!#1 0)}


\begin{pspicture}(-3.2,-0.4)(3.05,0.1) % boundry found manually
  \multido{\i = -3+1}{7}{%



Note that if the points are equidistantly distributed on the line, you can use the \multido macro to generalise the code.

Different colored dots



\def\Dot[#1](#2){\psdot[dotstyle = o, fillcolor = #1](!#2 0)}


\begin{pspicture}(-3.2,-0.4)(3.05,0.1) % boundry found manually
  \multido{\i = -3+1}{7}{%




Another example with PSTricks. Irrational numbers are the features of my answer!


    \pscircle[fillstyle=solid,fillcolor=#1](!#2 0){3pt}}

    \xpoint{2 sqrt} % the square root of 2
    \xpoint[red]{4 sqrt}% the square root of 4

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.