![如何绘制带有不同替代距离刻度标签的线性轴?](https://linux22.com/image/420799/%E5%A6%82%E4%BD%95%E7%BB%98%E5%88%B6%E5%B8%A6%E6%9C%89%E4%B8%8D%E5%90%8C%E6%9B%BF%E4%BB%A3%E8%B7%9D%E7%A6%BB%E5%88%BB%E5%BA%A6%E6%A0%87%E7%AD%BE%E7%9A%84%E7%BA%BF%E6%80%A7%E8%BD%B4%EF%BC%9F.png)
我需要帮助来绘制一个线性轴,该轴下方有刻度标签,彼此之间的距离逐渐不同,就像楼梯一样。我尝试使用 tikz 包绘制它,但我不知道该怎么做。我该怎么做?我附上了一些我需要的图像和编写的代码,我可以实现将所有刻度标签定位在与轴的不同距离处,但都在同一水平。此图表不是时间轴谢谢
这是我使用该代码所能得到的结果:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
% Dibujo los ejes...
\draw[thick,|->] (0,0)--(10,0) node[right] {$t$}; % Eje x
% Enumeración del eje x
\foreach \x/\xtext in {0/C_0, 1/C_1, 2/C_2, 3/C_3, 4/\cdots, 5/C_{\overline{p-1}}, 6/C_p, 7/C_{\overline{p+1}}, 8/\cdots, 9/C_{\overline{n-1}}, 10/C_n}
%\foreach \x/\xtext in {0/C_0, 1/C_1, 2/C_2, 3/C_3, 4/\cdots, 5/C_{\overline{(p-1)}}, 6/C_p, 7/C_{\overline{(p+1)}}, 8/\cdots, 9/C_{\overline{(n-1)}}, 10/C_n}
\draw[shift={(\x,0)}] (0pt,2pt)--(0pt,-2pt) node[below = 2cm] {$\xtext$};
%\node[below] at (0,0) {$C_0$};
\end{tikzpicture}
\end{center}
\end{document}
这就是我需要的:
答案1
像这样:
该代码只是一些\foreach
循环的集合,其中有一些小技巧可以跳过“间隙位置”。
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\draw[SteelBlue,thick,-LaTeX](1,0)-- ++(11,0);
\foreach \lab [count=\c] in {0,1,2,3,X,p-1,p,p+1,X,n-1,n} {
\if\lab X\relax% jump over gap
\node at (\c,0){//};
\else
\draw[SteelBlue,thick] (\c,0.2) -- ++(0,-0.4);
\draw[SteelBlue,dashed] (\c,0) -- ++(0,\c/2-6)node[below]{$C_{\lab}$};
\fi
}
\end{tikzpicture}
\end{center}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\draw[SteelBlue,thick,-LaTeX](1,0)-- ++(11,0);
\foreach \lab [count=\c] in {0,1,2,3,X,p-1,p,p+1,X,n-1,n} {
\if\lab X\relax% jump over gap
\node at (\c,0){//};
\else
\draw[SteelBlue,thick] (\c,0.2) -- ++(0,-0.4);
\draw[SteelBlue,dashed] (\c,0) -- ++(0,\c/2-6)
-- ++(12-\c,0)node[right]{$C_{\lab}$};
\fi
}
\end{tikzpicture}
\end{center}
\begin{center}
\begin{tikzpicture}[scale=0.8]
\draw[SteelBlue,thick,-LaTeX](1,0)-- ++(11,0);
\def\dc{0}
\foreach \lab [count=\c] in {0,1,2,3,X,p-1,p,p+1,X,n-1,n} {
\if\lab X\relax% jump over gap
\node at (\c,0){//};
% hacky...draw over the C_\labs we don't want
\draw[white,fill=white](\c-0.5,-0.5) rectangle (\c+0.5,-12);
% don't leave a line between skipped labels
\pgfmathparse{\dc+1}
\xdef\dc{\pgfmathresult}
\else
\draw[SteelBlue,thick] (\c,0.2) -- ++(0,-0.4);
\foreach \cc in {\c,...,11} {
\node at (\cc, \dc-\c) {$C_{\lab}$};
}
\fi
}
\end{tikzpicture}
\end{center}
\end{document}