# Draw dashed line with solid and empty circle using tikz

Problem:

Trying to get empty circles to work with tikz and add text to the right of the circles. I have not been able to find the correct command for these two issues.

Minimal Working Example (MWE):

\documentclass{article}
\usepackage{tikz, environ}
\usetikzlibrary{arrows.meta}

% --------------------------------------------------------------
% Scales tikzpicture to text width
% --------------------------------------------------------------

\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
\def\tikz@width{#1}%
\def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
\BODY
\end{lrbox}%
\pgfmathparse{#1/\wd\measure@tikzpicture}%
\edef\tikzscale{\pgfmathresult}%
\BODY
}
\makeatother

\begin{document}

\begin{scaletikzpicturetowidth}{\textwidth}
\begin{tikzpicture}[scale=\tikzscale, xscale=1.3]
\draw [thick] (0,0) -- (8,0);
\draw (0,-.2) -- (0, .2);
\draw (1,-.2) -- (1, .2);
\draw (2,-.2) -- (2, .2);
\draw (3,-.2) -- (3, .2);
\draw (4,-.2) -- (4, .2);
\draw (5,-.2) -- (5, .2);
\draw (6,-.2) -- (6, .2);
\draw (7,-.2) -- (7, .2);
\draw (8,-.2) -- (8, .2);
\draw[dashed, {Circle}-{Circle}] (0,-1) -- (4,-1);
\draw[dashed, {Circle}-{Circle}] (2,-1.75) -- (6,-1.75);
\draw[dashed, {Circle}-{Circle}] (2,-2.5) -- (4,-2.5);
\node[above] at (1,0.25){$-5$};
\node[above] at (2,0.25){$-4$};
\node[above] at (3,0.25){$-3$};
\node[above] at (4,0.25){$-2$};
\node[above] at (5,0.25){$-1$};
\node[above] at (6,0.25){$0$};
\node[above] at (7,0.25){$1$};
\node[align=right, below] at (7.5,-.4){Text here};
\end{tikzpicture}
\end{scaletikzpicturetowidth}

\end{document}


Current output:

Desired output:

• \draw[dashed, -o] (0,-1) -- (4,-1)node[right]{VO}; works for me. Add to preamble \usetikzlibrary{arrows}. – ferahfeza Jul 10 at 20:23

You are doing everything right when loading arrows.meta (since it supersedes arrows), you only need to add [open] for open circles and node[right]{...} for the texts. Of course, I do not know which texts you want and which of the circles should be open, so I added something generic and opened 50% of the circles.

\documentclass{article}
\usepackage{tikz, environ}
\usetikzlibrary{arrows.meta}

% --------------------------------------------------------------
% Scales tikzpicture to text width
% --------------------------------------------------------------

\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
\def\tikz@width{#1}%
\def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
\BODY
\end{lrbox}%
\pgfmathparse{#1/\wd\measure@tikzpicture}%
\edef\tikzscale{\pgfmathresult}%
\BODY
}
\makeatother

\begin{document}

\begin{scaletikzpicturetowidth}{\textwidth}
\begin{tikzpicture}[scale=\tikzscale, xscale=1.3]
\draw [thick] (0,0) -- (8,0);
\draw (0,-.2) -- (0, .2);
\draw (1,-.2) -- (1, .2);
\draw (2,-.2) -- (2, .2);
\draw (3,-.2) -- (3, .2);
\draw (4,-.2) -- (4, .2);
\draw (5,-.2) -- (5, .2);
\draw (6,-.2) -- (6, .2);
\draw (7,-.2) -- (7, .2);
\draw (8,-.2) -- (8, .2);
\draw[dashed, {Circle}-{Circle[open]}] (0,-1) -- (4,-1) node[right]{abc};
\draw[dashed, {Circle}-{Circle[open]}] (2,-1.75) -- (6,-1.75)node[right]{xyz};
\draw[dashed, {Circle}-{Circle[open]}] (2,-2.5) -- (4,-2.5)node[right]{uvw};
\node[above] at (1,0.25){$-5$};
\node[above] at (2,0.25){$-4$};
\node[above] at (3,0.25){$-3$};
\node[above] at (4,0.25){$-2$};
\node[above] at (5,0.25){$-1$};
\node[above] at (6,0.25){$0$};
\node[above] at (7,0.25){$1$};
\node[align=right, below] at (7.5,-.4){Text here};
\end{tikzpicture}
\end{scaletikzpicturetowidth}

\end{document}


• @AndréC I know all that but the OP correctly loads arrows.meta, which is appropriate because it is more powerful. – user121799 Jul 10 at 21:14
• @marmot Is there a way to get space between the empty circle and the text? – kexxcream Jul 10 at 21:25
• @kexxcream Yes, of course, you can add a dimension after right, replace e.g. \draw[dashed, {Circle}-{Circle[open]}] (0,-1) -- (4,-1) node[right]{abc}; by \draw[dashed, {Circle}-{Circle[open]}] (0,-1) -- (4,-1) node[right=3mm]{abc};. – user121799 Jul 10 at 21:26