我想在数字射线上标出间隔。下面是一个包含半开间隔的示例(我想从 c 到 1-b 再画一个)。我确信我实现此目的的方法可以改进……(尤其是因为它并不十分精确——我画了一个填充的矩形,但间隔在右侧是开放的)。有什么更好的方法可以实现此目的?
\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}
输出:
答案1
我想使用[-
和-)
箭头样式来实现这一点。这在没有半透明的情况下非常容易。半透明的方法可能可以改进。
我稍微改变了坐标,希望这不会太烦人。
\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}
编辑:按照 Harish Kumar 的建议添加圆角。