## 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 385 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:

\documentclass[border=5pt]{standalone}\usepackage{pgfplots}\pgfplotsset{compat=1.16} \begin{document}\begin{tikzpicture}\begin{axis}[    x=3mm,    axis y line=none,    axis x line=center,    xtick align=outside,    xtick={-5,0,...,30},    xmin=-7, xmax=33,     ymin=0, ymax=1,    xlabel=$x$,    xlabel style={anchor=north}]\addplot [nodes=draw, circle, inner sep=1.5pt]     coordinates {(-5,.1) (25,.1)}         node [fill, at start] {}        node [fill=white] {};\end{axis}\end{tikzpicture}\end{document}

A possible replacement for the command \addplot:

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

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 364 times

Bartman
Posts: 70
Joined: Fri Jan 03, 2020 2:39 pm
\documentclass[border=5pt]{standalone}\usepackage{pgfplots}\pgfplotsset{compat=1.16} \begin{document}\begin{tikzpicture}[    dot/.style={draw, fill=#1, circle, inner sep=1.5pt},    filled/.style={dot},    open/.style={dot=white}]\begin{axis}[    x=3mm,    axis y line=none,    axis x line=center,    xtick align=outside,    xtick={-5,0,...,30},    xmin=-7, xmax=33,     ymin=0, ymax=1,    xlabel=$x$,    xlabel style={anchor=north}]\addplot [black]    coordinates {(-5,.1) (25,.1)}         node [filled, at start] {}        node [open] {}        node [above, midway] {A};\end{axis}\end{tikzpicture}\end{document}

The other way:

\documentclass[border=5pt]{standalone}\usepackage{pgfplots}\pgfplotsset{compat=1.16} \begin{document}\begin{tikzpicture}[    dot/.style={draw, circle, inner sep=1.5pt},    filled/.style={dot, fill},    open/.style={dot}]\begin{axis}[    x=3mm,    axis y line=none,    axis x line=center,    xtick align=outside,    xtick={-5,0,...,30},    xmin=-7, xmax=33,     ymin=0, ymax=1,    xlabel=$x$,    xlabel style={anchor=north}]\draw    (-5,.1) node [filled] (filled) {}    (25,.1) node [open] (open) {}    (filled) -- node [above] {A} (open);\end{axis}\end{tikzpicture}\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 