使用 tikzpicture 绘制间隔线

使用 tikzpicture 绘制间隔线

我使用下面的图片作为我的线条的灵感。

在此处输入图片描述

在我的例子中,有 10 个具有不同间隔的实例。在一些(好吧,很多)帮助下,我设法编写了此代码

\documentclass[paper=a4, fontsize=11pt]{scrartcl} 
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}

\begin{document}
  \begin{tikzpicture}[every edge/.style={shorten <=1pt, shorten >=1pt}]
  \draw (0,0)  node [below] {0} -- (1,0) node [below] {1};
  % draw the tick marks
  \coordinate (p) at (0,2pt);
  \foreach \myprop/\mytext [count=\n] in {0.06/$p_1$,0.06/$p_2$,0.06/$p_3$,0.06/$p_4$,0.06/$p_5$,0.15/$p_6$,0.13/$p_7$,0.14/$p_8$,0.15/$p_9$,0.13/$p_10$}
  \draw [decorate,decoration={brace,amplitude=2}] (p)  edge [draw] +(0,-4pt) -- ++(\myprop,0) coordinate (p) node [midway, above=2pt, anchor=south] {\mytext} ;
  \path (1,2pt) edge [draw]  ++(0,-4pt);
\end{tikzpicture}
\end{document}

结果是

在此处输入图片描述

不是很令人印象深刻或吸引人。我是 tikzpicture 的新手,觉得这一切都让人不知所措。有人能帮忙吗?

答案1

您的代码在我看来或多或少还不错。唯一的问题是,您选择的尺寸太小了。将 x 坐标乘以 10 可得出:

在此处输入图片描述

代码

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}
%
\begin{document}
%
\begin{tikzpicture}[every edge/.style={shorten <=1pt, shorten >=1pt}]
  \draw (0,0)  node [below] {0} -- (10,0) node [below] {1};
  % draw the tick marks
  \coordinate (p) at (0,2pt);
  \foreach \myprop/\mytext [count=\n] in {0.6/$p_1$,0.6/$p_2$,0.6/$p_3$,0.6/$p_4$,0.6/$p_5$,1.5/$p_6$,1.3/$p_7$,1.4/$p_8$,1.5/$p_9$,1.3/$p_{10}$}
  \draw [decorate,decoration={brace,amplitude=2}] (p)  edge [draw] +(0,-4pt) -- ++(\myprop,0) coordinate (p) node [midway, above=2pt, anchor=south] {\mytext} ;
  \path (10,2pt) edge [draw]  ++(0,-4pt);
\end{tikzpicture}

\end{document}

相关内容