答案1
对于像这样的简单图表,您可以轻松地在 Ti 中编写代码钾Z。请注意,如果您想制作更复杂的图表,我会研究自动化其中的一些方面,但无论如何,这只是一个开始。
\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
gray box/.style={
fill=gray!20,
draw=gray,
minimum width={2*#1ex},
minimum height={2em},
},
annotation/.style={
anchor=north,
}
}
\begin{document}
\begin{tikzpicture}[node distance=-0.5pt]
\node [gray box=24] (p1) {\(P_{1}\)};
\node [gray box=3, right=of p1] (p2) {\(P_{2}\)};
\node [gray box=3, right=of p2] (p3) {\(P_{3}\)};
\node [annotation] at (p1.south west) {0};
\node [annotation] at (p1.south east) {24};
\node [annotation] at (p2.south east) {27};
\node [annotation] at (p3.south east) {30};
\end{tikzpicture}
\end{document}
答案2
\documentclass [tikz,border=2pt] {standalone}
\begin{document}
\small
\begin{tikzpicture}[line width=.7pt]
\draw[fill=gray!20] (0,0)node[below]{0} rectangle(5,1);
\draw[fill=gray!20] (5,0)node[below]{24}rectangle(6,1);
\draw[fill=gray!20] (6,0)node[below]{27}rectangle (7,1)node[below,yshift=-1cm]{30};
\path (2.5,.5)node{$P_1$} (5.5,.5)node{$P_2$} (6.5,.5)node{$P_3$};
\end{tikzpicture}
\end{document}