tikz 坐标位于某个坐标处

tikz 坐标位于某个坐标处

我一直在尝试协调另一个坐标上的节点。但是,我收到了一条错误消息。也许你们中有人知道如何解决这个问题?

提前非常感谢您。

\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{figure}[!htbp]
\centering
\begin{tikzpicture}[domain=0:5,scale=1,thick]
\draw[->] (0,0) -- (6,0) node[right] {$Employment$};
\draw[->] (0,0) -- (0,6) node[above] {$Wages$};
\draw[-] (5,0) coordinate (d_1) -- (0,4) coordinate (d_2);
\draw[-] (2.7,0) coordinate (s_1) -- (2.7,6) coordinate (s_2);
\draw[-] (1.5,0) coordinate (s_3)-- (1.5,6) coordinate (s_4);
\coordinate [label= right:$B$] (b) at (intersection of d_1--d_2 and s_1--s_2);
\fill[red] (b) circle (2pt);
\coordinate [label= right:$A$] (a) at (intersection of d_1--d_2 and s_3--s_4);
\coordinate [label= left:$W1$] (w1) at (0,$(b)$);
\draw[-] (w1) -- (b);
\end{tikzpicture}
\end{figure}
\end{document}

 

Package PGF Math Error: Unknown operator `$' or `$(' (in '$(b').
See the PGF Math package documentation for explanation. Type  H <return>  for immediate help.
l.82 ...rdinate [label= left:$W1$] (w1) at (0,$(b)
                                              $);

在此处输入图片描述

答案1

所以你真正的问题是这样的:如何获得 y 轴上另一个点高度上的点?

有很多方法可以做到这一点。这是其中一种方法,使用\path let

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[domain=0:5,scale=1,thick]
\draw[->] (0,0) -- (6,0) node[right] {$Employment$};
\draw[->] (0,0) -- (0,6) node[above] {$Wages$};
\draw[-] (5,0) coordinate (d_1) -- (0,4) coordinate (d_2);
\draw[-] (2.7,0) coordinate (s_1) -- (2.7,6) coordinate (s_2);
\draw[-] (1.5,0) coordinate (s_3)-- (1.5,6) coordinate (s_4);
\coordinate [label= right:$B$] (b) at (intersection of d_1--d_2 and s_1--s_2);
% moved down so it's not overdrawn by the blue line
%\fill[red] (b) circle (2pt);
\coordinate [label= right:$A$] (a) at (intersection of d_1--d_2 and s_3--s_4);
\path let \p1=(b) in
  coordinate [label= left:$W1$] (w1) at (0,\y1); % point on y-axis
\draw[blue] (w1) -- (b);
\fill[red] (b) circle (2pt);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

  • O为轴原点添加了新坐标
  • 使用正交坐标系-|确定坐标W1
  • 而 $Employment$ 和 $Wages$分别使用\textit{Employment}\textit{Wages}

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[thick]
% axis
\coordinate (O) at (0,0); % <-- added
\draw[->] (O) -- (6,0) node[right] {\textit{Employment}};
\draw[->] (O) -- (0,6) node[above] {\textit{Wages}};
%
\draw (5.0,0) coordinate (d_1) -- (0.0,4) coordinate (d_2);
\draw (2.7,0) coordinate (s_1) -- (2.7,6) coordinate (s_2);
\draw (1.5,0) coordinate (s_3) -- (1.5,6) coordinate (s_4);
%
\coordinate [label= right:$B$] (b) at (intersection of d_1--d_2 and s_1--s_2);
\draw[blue] (b -| O) node[left,text=black] {$W1$} -- (b);
\fill[red]  (b) circle (2pt);
\coordinate [label= right:$A$] (a)  at (intersection of d_1--d_2 and s_3--s_4);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

我不确定你的目标是什么,但我可以看到在 TeX 识别为有错误的行上,你指定了坐标(0,$(b)$)。这不是可解析的 TikZ 坐标。如果你想让它与位于同一位置b,那么只需写入(b)。如果你想做更复杂的事情,那么你做什么取决于更复杂的事情是什么。

相关内容