3

I have been trying to coordinate a node at another coordinate. However, I receive an error message. Maybe one of you have an idea how to solve it?

Thank you very much in advance.

\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)
                                              $);

enter image description here

6

So your real question is something like: How to get a point on the y-axis at the height of some other point?

There are a lot of ways to do this. Here is one, using \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}

enter image description here

7
  • added new coordinate O for axis origin
  • used orthogonal coordinate system -| for determining coordinate W1
  • instead $Employment$ and $Wages$ use \textit{Employment} and \textit{Wages} respectively

\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}

enter image description here

  • Thank you all! Understand it now and it works perfectly. – Eddy Oct 17 '17 at 6:35
  • @Eddy, if answer solve your problem (on the best way), you can accept them (by clicking on check mark at top left side of answer) :-) – Zarko Oct 17 '17 at 6:41
3

I'm not sure what your goal is, but I can see that on the line that TeX identifies as having the error, you have the coordinate specification (0,$(b)$). This is not a parseable TikZ coordinate. If you want it at the same location as b, then just write (b). If you want to do something more complicated then what you do depends on what that more complicated thing is.

  • Thanks for your quick reply. I would like do what you just wrote, using location b as another coordinate. After removing $ $, I still receive the following error message Package PGF Math Error: Unknown function b' (in '(b'). – Eddy Oct 16 '17 at 20:50
  • @Eddy to clarify: you probably wrote at (0,(b));, but you should just write at (b); – Mike Oct 16 '17 at 21:01
  • I just added the picture that I attempt to create, but i failed to draw the blue line beacuse of the error message. Thank you. – Eddy Oct 16 '17 at 21:08
  • @Eddy: (b) is a point... You just need the Y coordinate there... not the whole point (b). Search for x,y coordinates in tikz to learn about it until someone give the final answer – koleygr Oct 16 '17 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.