TransWikia.com

How to graph a number line with writings on top?

TeX - LaTeX Asked by Upwork yasir on May 22, 2021

here is the image which i want to put in LaTeX.

number line

I want to be able to draw the portion in yellow with tikz.

Please help.
Here’s the MWE, which is not at all okay:

usepackage{pgfplots}
begin{document}
    begin{tikzpicture}
        begin{axis}[
            axis x line=middle,
            axis y line=none,
            height=50pt,
            width=axisdefaultwidth,
            xmin=-10,
            xmax=10,
            ]
            addplot coordinates {(0,0) (5,0)};
        end{axis}
    end{tikzpicture}
end{document}

One Answer

  • Your MWE is not complete nor even close to desired image. You need to make yourself more familiar with tikz and pgfplots. Try to read their documentation (ad list inztroductionary chapters and sections), also see TeXample and pgfplots examples.
  • for this image is simpler to use tikz package:
documentclass[tikz, margin=3.14159]{standalone}
usetikzlibrary{arrows.meta,
                quotes}

begin{document}
    begin{tikzpicture}
draw[Straight Barb-Straight Barb]
    (0,0) to ["$x=-1$"] ++ (3,0) coordinate (a) 
          to ["$x=1$"]  ++ (2,0) coordinate (b)
          to ["$x=6$"]  ++ (3,0);
foreach x in {a,b}
    draw (a) ++ (0,1mm) -- ++ (0,-2mm)  node[below] {0}
          (b) ++ (0,1mm) -- ++ (0,-2mm)  node[below] {5};          
    end{tikzpicture}
end{document}

enter image description here

BTW, meaning/intention of this image is quite unclear ...

Correct answer by Zarko on May 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP