Tikz:与轴的交叉点错误

Tikz:与轴的交叉点错误

在下面的代码中,与 y 轴相交的虚线位置不对,我不知道我哪里犯了错误(如果有的话):

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{intersections,calc}

\begin{document}

\begin{tikzpicture}
    \draw [<->] (0,5) node (ejey) [left]{$\omega$} |- (5.5,0)  node (ejex)
    [right]{$l$};
    \draw [name path = ls] (0.5,0.5) coordinate (a) -- (4.5,4.5) node
    (b) [right] {$l^{s}(\omega, r)$};
    \draw [name path = ld] (0.5,4.5) coordinate (c) -- (4.5,0.5) node
    (d) [right] {$l^{d}(\omega)$};
    \path [name intersections={of=ls and ld, by=i}];
    \draw [dashed] (ejey |- i) node [left] {$\omega_{0}^{*}$} -| (i |- ejex)
    node [below] {$l_{0}^{*}$};
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

出现问题的原因是虚线从节点中心的 x 坐标开始ejey,即 omega 的中心。要使线与轴齐平,您可以使用

(ejey.east |- i)

代替

(ejey |- i)

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{intersections,calc}

\begin{document}

\begin{tikzpicture}
    \draw [<->] (0,5) node (ejey) [left]{$\omega$} |- (5.5,0)  node (ejex) [right]{$l$};
    \draw [name path = ls] (0.5,0.5) coordinate (a) -- (4.5,4.5) node (b) [right] {$l^{s}(\omega, r)$};
    \draw [name path = ld] (0.5,4.5) coordinate (c) -- (4.5,0.5) node (d) [right] {$l^{d}(\omega)$};
    \path [name intersections={of=ls and ld, by=i}];
    \draw [dashed] (ejey.east |- i) node [left] {$\omega_{0}^{*}$} -| (i |- ejex) node [below] {$l_{0}^{*}$};
\end{tikzpicture}

\end{document}

答案2

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{intersections,calc}

\begin{document}

\begin{tikzpicture}
    \draw [<->] (0,5) coordinate (ejey) |- (5.5,0) coordinate (ejex);
    \node [left] at (ejey) {$\omega$};
    \node [right] at (ejex)  {$l$};
    \draw [name path = ls] (0.5,0.5) coordinate (a) -- (4.5,4.5) node    (b) [right] {$l^{s}(\omega, r)$};
    \draw [name path = ld] (0.5,4.5) coordinate (c) -- (4.5,0.5) node    (d) [right] {$l^{d}(\omega)$};
    \path [name intersections={of=ls and ld, by=i}];
    \draw [dashed] (ejey |- i) node [left] {$\omega_{0}^{*}$} -| (i |- ejex)    node [below] {$l_{0}^{*}$};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容