## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Number Line Help Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
tpa77l3
Posts: 19
Joined: Mon Feb 24, 2020 9:49 pm

### Number Line Help

Hey guys,

I'm completely new to LaTeX and have thrown myself somewhat in the deep end when starting a maths course.

I would like some help creating a number line with another line above it. The higher of the two lines requires dots on either end; one filled and one not. Example attached.

Any pointers would be greatly appreciated. Thanks in advance.

Screenshot 2020-02-24 at 20.06.44.png (35.01 KiB) Viewed 386 times

Bartman
Posts: 70
Joined: Fri Jan 03, 2020 2:39 pm
It should be easier for beginners to create the drawing with pgf/TikZ. My solution uses pgfplots:

1. \documentclass[border=5pt]{standalone}
2. \usepackage{pgfplots}
3. \pgfplotsset{compat=1.16}
4.
5. \begin{document}
6. \begin{tikzpicture}
7. \begin{axis}[
8. x=3mm,
9. axis y line=none,
10. axis x line=center,
11. xtick align=outside,
12. xtick={-5,0,...,30},
13. xmin=-7, xmax=33,
14. ymin=0, ymax=1,
15. xlabel=$x$,
16. xlabel style={anchor=north}
17. ]
18. \addplot [nodes=draw, circle, inner sep=1.5pt]
19. coordinates {(-5,.1) (25,.1)}
20. node [fill, at start] {}
21. node [fill=white] {}
22. ;
23. \end{axis}
24. \end{tikzpicture}
25. \end{document}

A possible replacement for the command \addplot:

1. \draw [nodes=draw, circle, inner sep=1.5pt]
2. (-5,.1) node (filled) [fill] {}
3. (25,.1) node (open) {}
4. (filled) -- (open)
5. ;

tpa77l3
Posts: 19
Joined: Mon Feb 24, 2020 9:49 pm
This is perfect - thank you!

Just one more addition I need to may if you wouldn't mind. I need to include a label above the top line as below:

Screenshot 2020-02-25 at 05.50.46.jpg (27.29 KiB) Viewed 365 times

Bartman
Posts: 70
Joined: Fri Jan 03, 2020 2:39 pm
1. \documentclass[border=5pt]{standalone}
2. \usepackage{pgfplots}
3. \pgfplotsset{compat=1.16}
4.
5. \begin{document}
6. \begin{tikzpicture}[
7. dot/.style={draw, fill=#1, circle, inner sep=1.5pt},
8. filled/.style={dot},
9. open/.style={dot=white}
10. ]
11. \begin{axis}[
12. x=3mm,
13. axis y line=none,
14. axis x line=center,
15. xtick align=outside,
16. xtick={-5,0,...,30},
17. xmin=-7, xmax=33,
18. ymin=0, ymax=1,
19. xlabel=$x$,
20. xlabel style={anchor=north}
21. ]
23. coordinates {(-5,.1) (25,.1)}
24. node [filled, at start] {}
25. node [open] {}
26. node [above, midway] {A}
27. ;
28. \end{axis}
29. \end{tikzpicture}
30. \end{document}

The other way:

1. \documentclass[border=5pt]{standalone}
2. \usepackage{pgfplots}
3. \pgfplotsset{compat=1.16}
4.
5. \begin{document}
6. \begin{tikzpicture}[
7. dot/.style={draw, circle, inner sep=1.5pt},
8. filled/.style={dot, fill},
9. open/.style={dot}
10. ]
11. \begin{axis}[
12. x=3mm,
13. axis y line=none,
14. axis x line=center,
15. xtick align=outside,
16. xtick={-5,0,...,30},
17. xmin=-7, xmax=33,
18. ymin=0, ymax=1,
19. xlabel=$x$,
20. xlabel style={anchor=north}
21. ]
22. \draw
23. (-5,.1) node [filled] (filled) {}
24. (25,.1) node [open] (open) {}
25. (filled) -- node [above] {A} (open)
26. ;
27. \end{axis}
28. \end{tikzpicture}
29. \end{document}
Last edited by Bartman on Wed Feb 26, 2020 2:33 am, edited 1 time in total.

tpa77l3
Posts: 19
Joined: Mon Feb 24, 2020 9:49 pm
Much appreciated