我看过另一个例子,但很难适应我的需求。Tikz 对我来说很新。
\begin{center}
\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{center}
Latex 将所有值挤压在一起而不是将它们分散到 0 到 1 的轴上。
答案1
以下是修改内容的一种方法:
\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{decorations.pathreplacing,calc,positioning}
\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 {1/$p_1$,2/$p_2$,.5/$p_3$,1/$p_4$,5/\dots,.5/$p_n$}
\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}
答案2
这是一个例子。根据你在问题后面的评论,我放了 10 个段(11 个刻度)。
\documentclass[tikz,border=7mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
% draw segment and ticks
\draw[-](0,0)--(10,0) foreach~in{0,...,10}{(~,-2pt)--(~,2pt)};
% draw braces and labels
\foreach[count=\j]\i in{0,...,9}
\draw[decorate,decoration=brace](\i cm + 1pt,3pt) -- node[above,font=\scriptsize]{$p_{\j}$} (\j cm - 1pt,3pt);
\end{tikzpicture}
\end{document}