我怎样才能在该 tikzpicture 的蓝线上方写字?
\begin{tikzpicture}[
scale=5,
IS/.style={blue, thick},
LM/.style={red, thick},
axis/.style={very thick, ->, >=stealth', line join=miter},
important line/.style={thick}, dashed line/.style={dashed, thin},
every node/.style={color=black},
dot/.style={circle,fill=black,minimum size=4pt,inner sep=0pt,
outer sep=-1pt},
]
% axis
\draw[axis,-] (2.5,0) node(xline)[right] {$O_B$} -|
(0,2.5) node(yline)[left] {$w$};
\draw[axis,-](2.5,0)--(2.5,2.5);
\node (0,0) [left]{$O_A$};
\draw[-, Blue] (0,2)--(1.4,.6)
\draw[-, Blue] (2.5,2)--(.8,.6);
\draw[dashed] (0,.87) node[left] {$w_0^*$}--(2.5,.87) node[right] {$w_0^*$};
\node[dot,label=above:$\epsilon_0$] at (1.13,.87) (int1) {};
\draw[dashed] (1.13,0) node[below]{$E_0$}--(1.13,0.87);
\end{tikzpicture}
上述代码的运行结果:
我想要一些类似这张图片中的“ABC”和“CBA”的东西。
答案1
node[pos=0.5,sloped,above]
按照我的以下代码使用。说明:
pos=0.5
将节点置于路径中间,sloped
旋转文本,使其与插入位置的路径斜率平行,above
是不言自明的。
请注意,您的代码在第 3 条命令末尾缺少一个分号draw
。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[%
scale=5,%
IS/.style={blue, thick},%
LM/.style={red, thick},%
axis/.style={very thick, ->, >=stealth', line join=miter},%
important line/.style={thick}, dashed line/.style={dashed, thin},%
every node/.style={color=black},%
dot/.style={circle,fill=black,minimum size=4pt,inner sep=0pt,%
outer sep=-1pt},%
]
% axis
\draw[axis,-] (2.5,0) node(xline)[right] {$O_B$} -|
(0,2.5) node(yline)[left] {$w$};
\draw[axis,-] (2.5,0) -- (2.5,2.5);
\node (0,0) [left]{$O_A$};
\draw[-, blue] (0,2)--(1.4,.6) node[pos=0.5,sloped,above] {$foo$};
\draw[-, blue] (2.5,2)--(.8,.6) node[pos=0.5,sloped,above] {$bar$};
\draw[dashed] (0,.87) node[left] {$w_0^*$} -- (2.5,.87) node[right] {$w_0^*$};
\node[dot,label=above:$\epsilon_0$] at (1.13,.87) (int1) {};
\draw[dashed] (1.13,0) node[below]{$E_0$}--(1.13,0.87);
\end{tikzpicture}
\end{document}