和我之前的问题一致如何绘制带有不同替代距离刻度标签的线性轴?,这个问题已由@user30471 成功回答,现在我需要根据这些图表和他或她的答案进行修改,但我不知道如何修改代码来实现它。我留下了我现在需要做的事情的图片。非常感谢!
这是我迄今为止尝试过的
\begin{center}
\begin{tikzpicture}[scale=1]
\draw[SteelBlue,thick,-LaTeX](1,0)-- ++(12,0) node[right] [right=0.5cm, below]{$t$};
\foreach \lab [count=\c] in {\frac{1}{(1+i)^n},\frac{1}{(1+i)^{n-1}},X,\frac{1}{(1+i)^{p+1}},\frac{1}{(1+i)^p},\frac{1}{(1+i)^{p-1}},X,\frac{1}{(1+i)^3},\frac{1}{(1+i)^2},\frac{1}{(1+i)},X} {
\if\lab X\relax% jump over gap
\node at (\c,0)[SteelBlue,thick]{//};
\else
\draw[SteelBlue,thick] (\c,0.2) -- ++(0,-0.4);
\draw[SteelBlue] (13-\c,0) -- ++(0,\c/2-6)
-- ++(\c-12,0)node[left]{$\lab$};
\fi
}
\end{tikzpicture}
\结束{中心}
但我无法理解轴标签位置的逻辑,也不知道如何放置标签和引用,因为标签与引用不同
答案1
\documentclass[tikz, margin=3.14159mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[>=Straight Barb,
lbl/.style = {text depth=1ex, inner sep=1pt}
]
\draw[blue,->] (0,0) -- (9,0);
% ticks
\foreach \i [count=\j from 0] in {0 , 1, 2, 3, (p-1), p, (n-1), n}
\draw (1.2*\j,1mm) node[lbl, above] {$\mathsf{C_{\i}}$}
-- ++ (0,-2mm)
\ifnum\j>0 node[below] {$\mathsf{\frac{1}{(1+i)^{\i}}}$}\fi;
\draw[double] (1.2*3.5,1mm) -- ++ (-1mm,-2mm)
(1.2*5.5,1mm) -- ++ (-1mm,-2mm);
\end{tikzpicture}
\end{document}
附录: 或者从编辑过的问题中可以理解,对于问题的第一部分,您希望有:
\documentclass[tikz, svgnames, margin=3.14159mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[>=Straight Barb,
lbl/.style = {text depth=1ex, inner sep=1pt}
]
\draw[SteelBlue, thick, ->] (0,0) -- (12,0);
\draw[double] (1.2*3.5,1mm) -- ++ (-1mm,-2mm)
(1.2*6.5,1mm) -- ++ (-1mm,-2mm);
% ticks
\foreach \i [count=\j from 0] in {0 , 1, 2, 3, (p-1), p, (p+1), (n-1), n}
{
\draw[SteelBlue] (1.2*\j,1mm) node[lbl, above] {$\mathsf{C_{\i}}$}
-- ++ (0,-2mm) coordinate (t\j);
\ifnum\j>0
\node (n\j) [left,inner sep=0pt] at (0,-0.6*\j) {$\mathsf{\frac{1}{(1+i)^{\i}}}$};
\draw[densely dashed,SteelBlue] (n\j.4) -| (t\j);
\fi;
}
\end{tikzpicture}
\begin{tikzpicture}[>=Straight Barb,
lbl/.style = {text depth=1ex, inner sep=1pt}
]
\draw[SteelBlue, thick, ->] (0,0) -- (12,0);
\draw[double] (1.2*3.5,1mm) -- ++ (-1mm,-2mm)
(1.2*6.5,1mm) -- ++ (-1mm,-2mm);
% ticks
\foreach \i [count=\j from 0] in {0 , 1, 2, 3, (p-1), p, (p+1), (n-1), n, n+1}
{
\draw[SteelBlue] (1.2*\j,1mm) node[lbl, above] {$\mathsf{C_{\i}}$}
-- ++ (0,-2mm) coordinate (t\j);
}
%
\path[draw=SteelBlue,densely dotted]
(t0) -- ++ (0,-2) node[below] {$a(1,n,i)$}
(t1) -- ++ (0,-1) node[below] {$a(0,n,i)$}
(t8) -- ++ (0,-2) node[below] {$s(1,n,1)$}
(t9) -- ++ (0,-1) node[below] {$a(0,n,1)$}
;
\end{tikzpicture}
\begin{tikzpicture}[>=Straight Barb,
lbl/.style = {text depth=1ex, inner sep=1pt, align=left}
]
\draw[SteelBlue, thick, ->] (0,0) -- (12,0);
\draw[double] (1.2*3.5,1mm) -- ++ (-1mm,-2mm)
(1.2*6.5,1mm) -- ++ (-1mm,-2mm);
% ticks
\foreach \i [count=\j from 0] in {0 , 1, 2, 3, (p-1), p, (p+1), (n-1), n}
{
\draw[SteelBlue] (1.2*\j,1mm) node[lbl, above] {$\mathsf{C_{\i}}$}
-- ++ (0,-2mm) coordinate (t\j);
}
%
\begin{scope}[nodes={lbl,below=3mm, font=\footnotesize}]
\path
(t0) node {$\mathsf{C_{(0)}}$}
(t1) node {$\mathsf{I_{(0,1)}}$\\
$\mathsf{C_{(1)}}$}
(t2) node {$\mathsf{I_{(1,2)}}$\\
$\mathsf{I_{(0,2)}}$\\
$\mathsf{C_{(2)}}$}
%
(t5) node {$\mathsf{I_{(p-1,p)}}$\\
$\mathsf{I_{(0,p)}}$\\
$\mathsf{C_{(p)}}$}
%
(t7) node {$\mathsf{I_{(n-2,n-1)}}$}
%
(t8) node {$\mathsf{I_{(n-1,n)}}$\\
$\mathsf{I_{(0,n)}}$\\
$\mathsf{C_{(n)}}$}
;
\end{scope}
\end{tikzpicture}
\end{document}