最近我一直在制作一些图表,我从 Tikz 包开始,但我不知道如何从这个开始:
我已尝试过这个:
\begin{tikzpicture}
[every node/.style={text depth=0pt}] % align node text
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (15,0);
\draw[|-|]
(A)
node at (A) [above=5pt] {$1$}
node at (A) [below=5pt] {$0$}
--
(B);
\draw[-|]
(B)
node at (B) [above=5pt] {$(1+R_{i,\tau-1})^\tau-1$}
node at (B) [below=5pt] {$i+\tau-1$};
--
(C);
node at (C) [above=5pt] {$(1+R_{i,\tau-1})^{\tau-1}(1+F_{i,\tau})^{\tau}$}
node at (C) [below=5pt] {$i+\tau$};
\end{tikzpicture}
提前致谢。
答案1
所以,你几乎已经了解了:
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
[every node/.style={text depth=0pt,text height=1.5ex}]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (15,0);
\draw[|-|]
(A)
node (Aa) at (A) [above=10pt] {$1$}
node (Ab) at (A) [below=5pt] {$i$}
node (Ac) at (A) [below=20pt] {$1$}
--
(B);
\draw[-|]
(B)
node (Ba) at (B) [above=10pt] {$(1+R_{i,\tau-1})^{\tau-1}$}
node (Bb) at (B) [below=5pt] {$i+\tau-1$} % omit ; here
--
(C) % omit ; here as well
node (Ca) at (C) [above=10pt] {$(1+R_{i,\tau-1})^{\tau-1}(1+F_{i,\tau})^{\tau}$}
node (Cb) at (C) [below=5pt] {$i+\tau$}
node (Cc) at (C) [below=20pt] {$(1+R_{i,\tau})^{\tau}$};
\draw[-latex] (Aa) -- (Ba);
\draw[-latex] (Ba) -- (Ca);
\draw[-latex] (Ac) -- (Cc);
\end{tikzpicture}
\end{document}
可以使用 来命名节点\node (name) at (0,0) {...}
,就像命名坐标一样。这样,您以后可以引用这些节点,例如使用\draw
命令连接它们。
编辑:添加text height=1.5ex
以使箭头完全水平。(感谢 Earthliŋ!)
答案2
编辑: 修正了顶线上节点的位置。现在线是直的。
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 5mm,
every node/.style = {font=\small}
]
\coordinate[label=below:$i$] (A) at (0,0);
\coordinate[label=below:$i+\tau-1$] (B) at (3,0);
\coordinate[label=below:$i+\tau$] (C) at (9,0);
\draw[|-|] (A) -- (B);
\draw[-|] (B) -- (C);
\node (A') [above=of A] {1};
\node (B') [at={(A'-| B)}] {$(1+R_{i,\tau-1})^{\tau-1}$};
\node (C') [at={(A'-| C)}] {$(1+R_{i,\tau-1})^{\tau-1}(1+F_{i,\tau})^{\tau}$};
\draw[->] (A') edge (B') (B') to (C');
\node (A'') [below=of A] {1};
\node (C'') [below=of C] {$(1+R_{i,\tau})^\tau$};
\draw[->] (A'') to (C'');
\end{tikzpicture}
\end{document}
- 基本线的标签由坐标标签确定
- 在定义坐标上方/下方的节点之间绘制上方和下方的线
- 图中是使用的
tikz
库poaitioning
- 由于图像很长,我将坐标从 缩短
(15,0)
到(9,0)