9

I would like to indicate intervals on a ray of numbers. Here is an example including a half-open interval (I would like to draw another one from c to 1-b). I am sure my method to achieve this can be improved... (especially since it is not really exact -- I draw a filled rectangle but the interval is open to the right). What's a better way to achieve this?

\documentclass{scrartcl}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[mydrawstyle/.style={draw=black, very thick}, x=1mm, y=1mm, z=1mm]
  \draw[mydrawstyle, ->](-2,30)--(66,30) node at (-6,30)[left]{$x=1$};
  \draw[mydrawstyle](0,28)--(0,32) node[below=10]{$0$};
  \draw[mydrawstyle](10,28)--(10,32) node[above=4]{$c$};
  \draw[mydrawstyle](25,28)--(25,32) node[below=10]{$1-b$};
  \draw[mydrawstyle](50,28)--(50,32) node[below=10]{$1-a$};
  \draw[mydrawstyle](60,28)--(60,32) node[below=10]{$1$};
  \fill[fill=blue, opacity=0.2](0,29)--(0,31)--(10,31)--(10,29)--(0,29);
  \draw[mydrawstyle, draw=blue](1,29)--(0,29)--(0,31)--(1,31);
  \draw[mydrawstyle, draw=blue](10,30) arc (0:45:1.8);
  \draw[mydrawstyle, draw=blue](10,30) arc (0:-45:1.8);
\end{tikzpicture}
\end{document}

Output:

enter image description here

1 Answers1

11

I would like to do this using the [- and -) arrow stylings. This is very easy without the translucency. The approach to translucency can probably be improved.

I changed the coordinates a bit, I hope this isn't too annoying.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

%Without Transparency:
\begin{tikzpicture}[scale=7]
\draw[->, thick] (-0.1,0) -- (1.1,0);
\foreach \x/\xtext in {0/0,0.2/,0.4/$1-b$,0.8/$1-a$,1}
    \draw[thick] (\x,0.5pt) -- (\x,-0.5pt) node[below] {\xtext};
\draw (0.2,0.5pt) node[above] {$c$};
\draw[[-), ultra thick, blue] (0,0) -- (0.2,0);
\draw (-0.25,0) node {$x=1$};
\end{tikzpicture}

%With Transparency    
\begin{tikzpicture}[scale=7]
\draw[->, thick] (-0.1,0) -- (1.1,0);
\foreach \x/\xtext in {0/0,0.2/,0.4/$1-b$,0.8/$1-a$,1}
    \draw[thick] (\x,0.5pt) -- (\x,-0.5pt) node[below] {\xtext};
\draw (0.2,0.5pt) node[above] {$c$};
\draw[[-, ultra thick, blue] (0,0) -- (0.01,0);
\draw[-), ultra thick, blue] (0.19,0) -- (0.2,0);
\fill[opacity = 0.2, blue,rounded corners=1ex] (0,-.16ex) -- (0.2, -.16ex) -- (0.2, .16ex) -- (0,.16ex) -- cycle;
\draw (-0.25,0) node {$x=1$};
\end{tikzpicture}

\end{document}

enter image description here

Edit: Added rounded corners as suggested by Harish Kumar.

  • Hi, this looks awesome (especially when combining the two approaches). I ran into another problem: If you replace [-) by [-], the closing bracket causes the error Package tikz Error: Giving up on this path. Did you forget a semicolon?. How would you draw a [-] arrow/interval then? I tried to escape the closing brackets in various ways, but didn't succeed – Marius Hofert Nov 12 '13 at 08:00
  • 1
    Got it, {[-]} works :-) – Marius Hofert Nov 12 '13 at 08:04