![添加一些简单标签](https://linux22.com/image/394602/%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%BA%9B%E7%AE%80%E5%8D%95%E6%A0%87%E7%AD%BE.png)
由于我是 Tikz 的初学者,我想问一下在我的线条中添加标签的最佳方法是什么,如图所示:
这是代码:
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning,arrows.meta}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm]
\draw[thick,->] (0,0) -- (4.5,0) node[anchor=north west] {\small state 1};
\draw[thick,->] (0,0) -- (0,4.5) node[anchor=south east] {\small state 2};
\coordinate (A) at (0,0);
\coordinate (B) at (3,4);
\draw [extended line=0.5cm, <->] (A) -- (B) coordinate[midway] (M);
\draw [extended line=2.5cm, <->] ($(M)!0.5cm!270:(A)$) -- ($(M)!0.5cm!90:(A)$);
\node [dot=$x^{*}$] at (M) {};
\fill [red] (M) circle [radius=2pt] ;
\end{tikzpicture}
\end{document}
答案1
node[pos=0.9,right]{Payoff space $X$}
只需在路径中添加类似的内容即可。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
% \usetikzlibrary{positioning,arrows.meta} % <-not used here
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm]
\draw[thick,->] (0,0) -- (4.5,0) node[anchor=north west,font=\small] {state 1};
\draw[thick,->] (0,0) -- (0,4.5) node[anchor=south east,font=\small] {state 2};
\coordinate (A) at (0,0);
\coordinate (B) at (3,4);
\draw [extended line=0.5cm, <->] (A) -- (B) coordinate[midway] (M)
node[pos=0.9,right=1em]{Payoff space $X$};
\draw [extended line=2.5cm, <->] ($(M)!0.5cm!270:(A)$) -- ($(M)!0.5cm!90:(A)$)
node[pos=2.25,right=1em]{$m=x^*+\varepsilon$ space of discount factors};
\node [dot=right:$x^{*}$] at (M) {};
\fill [red] (M) circle [radius=2pt] ;
\end{tikzpicture}
\end{document}
至于您的附加问题:这里有一个建议。请注意,我extended line
从第二行删除了,因为它使 IHMO 的事情变得更加复杂。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
% \usetikzlibrary{positioning,arrows.meta} % <-not used here
\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm]
\draw[thick,->] (0,0) -- (4.5,0) node[anchor=north west,font=\small] {state 1};
\draw[thick,->] (0,0) -- (0,4.5) node[anchor=south east,font=\small] {state 2};
\coordinate (A) at (0,0);
\coordinate (B) at (3,4);
\draw [extended line=0.5cm, <->] (A) -- (B) coordinate[midway] (M)
node[pos=0.9,right=1em]{Payoff space $X$};
\draw [ <->] ($(M)!3cm!270:(A)$) -- ($(M)!3cm!90:(A)$)
node[pos=0.9,right=1em]{$m=x^*+\varepsilon$ space of discount factors}
coordinate[pos=0.75] (x);
\draw[blue,-latex] (0,0) -- (x);
\node [dot=right:$x^{*}$] at (M) {};
\fill [red] (M) circle [radius=2pt] ;
\end{tikzpicture}
\end{document}