我复制了下面的图
通过以下 MWE
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1}]
\coordinate (A) at (0,0);
\coordinate (M) at (2.8,2.8);
\draw[thick, ->](0,0)--(4.5,0) node[anchor=north west, font=\small]{state 1 payoff};
\draw[thick, ->](0,0)--(0,4.5) node[anchor=south east, font=\small]{state 2 payoff};
\draw[dashed, ->] (0,0)--(2.8,2.8);
\draw ($(A)!1.5!270:(1.2,1.6)$)--($(A)!3cm!90:(1.2,1.6)$) node[pos=0.1, right=1pt, font=\small]{price=0 (excess returns)};
\draw[blue,-latex] (0,0)--(1.2,1.6) coordinate[pos=2.8] (y) node[anchor=south east, font=\small]{$\Phi$};
\draw[blue, dashed] (1.2,1.6)--(y) coordinate[pos=0.1](z1) coordinate[pos=0.8](z2);
\foreach \X in {1,2}
{\draw ($(z\X)!2.5cm!270:(A)$) -- ($(z\X)!4cm!90:(A)$) node[pos=0.8,right=1pt, font=\small]{price=$\X$};
}
\draw (intersection cs: first line={($(z1)!2.5cm!270:(A)$)--($(z1)!4cm!90:(A)$)}, second line={(A)--(M)})
node[fill, inner sep=1pt,circle, font=\small, dot=above right:riskfree rate]{} coordinate(x);
\draw (0:0.5) arc (0:45:0.5) node[pos=0.5,right=0.5pt, font=\tiny]{$45^{o}$};
\end{tikzpicture}
\end{document}
这是第一次尝试,有些地方需要修复,所以我的代码看起来很乱。我想知道如何在循环内绘制 price=0 线foreach
,就像我绘制其他两条垂直线一样。我尝试通过定义坐标将其包含在代码中z1,z2,z3
,但我认为问题出在 的位置z1
,该位置设置在原点。我想我对垂直线的语法仍然有点困惑。此外,我想包含点“状态 1 或有债权”,它应该位于垂直于 x 轴的线与 x 轴本身的交点处。我试过,\node[...] at (intersection...) {};
但没有成功。谢谢。
答案1
是的,正如您所怀疑的那样,您无法绘制长度为 0 的直线的正交线。以下循环执行所有三条正交线。为了使其工作,我添加了一个辅助坐标aux
。附加文本\X=0
通过添加\ifnum\X=0\relax (excess returns)\fi
,使其仅出现在那里。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1}]
\coordinate (A) at (0,0);
\coordinate (M) at (2.8,2.8);
\draw[thick, ->](A)--(4.5,0) node[anchor=north west, font=\small]{state 1 payoff};
\draw[thick, ->](A)--(0,4.5) node[anchor=south east, font=\small]{state 2 payoff};
\draw[dashed, ->] (A)--(2.8,2.8);
\draw[blue,-latex] (A)--(1.2,1.6) coordinate[pos=2.8] (y) node[anchor=south east, font=\small]{$\Phi$}
coordinate[pos=0](z0) coordinate[pos=-0.4](aux);
\draw[blue, dashed] (1.2,1.6)--(y) coordinate[pos=0.1](z1) coordinate[pos=0.8](z2);
\foreach \X in {0,1,2}
{\draw ($(z\X)!2.5cm!270:(aux)$) -- ($(z\X)!4cm!90:(aux)$)
node[pos=0.8,right=1pt, font=\small]{price=$\X$ \ifnum\X=0\relax (excess returns)\fi};
}
\draw (intersection cs: first line={($(z1)!2.5cm!270:(A)$)--($(z1)!4cm!90:(A)$)}, second line={(A)--(M)})
node[fill, inner sep=1pt,circle, font=\small, dot=above right:riskfree rate]{} coordinate(x);
\draw (0:0.5) arc (0:45:0.5) node[pos=0.5,right=0.5pt, font=\tiny]{$45^{o}$};
\end{tikzpicture}
\end{document}