4

I am trying to draw a shift arrow from one point to the next, but it doesn't seem to work. Here is my code:

\begin{tikzpicture}
%Axis
\draw [<->] (0,5) node (yaxis) [left] {$P$} -- (0,0) node[below left] {(0,0)} -- (5,0) node (xaxis) [below] {$B$};
%Title
\draw (3,5) node[above, xshift=-10] {Corporate Bonds};
%Supply
\draw[->, red] (1,1) coordinate (s_1) -- (4,4) coordinate (s_2) node[above right] {$B^{s}$};
%Demand
\draw[->, blue] (1,4) coordinate (d_1) -- (4,1) coordinate (d_2) node[below right] {$B^{d}$};
%Save Intersection (equilibrium)
\coordinate (c) at (intersection of s_1--s_2 and d_1--d_2);
%Intersection (equilibrium)
\draw[dashed] (yaxis |- c) node[left] {$P^e$} -| (xaxis -| c) node[below] {$B^e$};
\fill[black] (c) circle (2pt);
%Demand After
\draw[->, blue, xshift=20, yshift=20] (1,4) coordinate (d_1) -- (4,1) coordinate (d_2) node[below right] {$B^{d'}$};
%Save Intersection (after equilibrium)
\coordinate (d) at (intersection of s_1--s_2 and d_1--d_2);
%Intersection (after equilibrium)
\draw[dashed] (yaxis |- d) node[left] {$P'$} -| (xaxis -| d) node[below] {$B'$};
\fill[black] (d) circle (2pt);
\draw[->, xshift=20, yshift=20] (c) -- (d); // <-- this is the arrow part I want to do
\end{tikzpicture}

Here is the picture:

enter image description here

I have the arrows pointing the right directions, but I want the arrows to shift away from the two intersection points so that the reader can see it better. However, when I use « xshift » or « yshift », it doesn't even shift the arrows at all; the arrows simply stay put where they are.

1
  • May be you can also consider draw a shorter arrow with shorten < and shorten > options: \draw[|->, xshift=20, yshift=20, shorten >=3pt, shorten <=3pt] (c) -- (d);
    – Ignasi
    Jun 14, 2014 at 8:29

4 Answers 4

3

You can't shift or rotate a shape by global operation, you have to specify it explicitely for each shape or by canvas transformations.

Edit :

Another solution is to use :

\draw[->,thick] let \p1 = ($(d)-(c)$)
    in
    ($(c)+1.5*(\y1,-\x1)$)--++(\x1,\y1) ;

The 1.5 is only a factor to move the arrow right (if >0) and left (if <0).

enter image description here

\documentclass[tikz]{standalone}
\usepackage{}
\usetikzlibrary{}

\begin{document}

\begin{tikzpicture}
%Axis
\draw [<->] (0,5) node (yaxis) [left] {$P$} -- (0,0) node[below left] {(0,0)} -- (5,0) node (xaxis) [below] {$B$};
%Title
\draw (3,5) node[above, xshift=-10] {Corporate Bonds};
%Supply
\draw[->, red] (1,1) coordinate (s_1) -- (4,4) coordinate (s_2) node[above right] {$B^{s}$};
%Demand
\draw[->, blue] (1,4) coordinate (d_1) -- (4,1) coordinate (d_2) node[below right] {$B^{d}$};
%Save Intersection (equilibrium)
\coordinate (c) at (intersection of s_1--s_2 and d_1--d_2);
%Intersection (equilibrium)
\draw[dashed] (yaxis |- c) node[left] {$P^e$} -| (xaxis -| c) node[below] {$B^e$};
\fill[black] (c) circle (2pt);
%Demand After
\draw[->, blue, xshift=20, yshift=20] (1,4) coordinate (d_1) -- (4,1) coordinate (d_2) node[below right] {$B^{d'}$};
%Save Intersection (after equilibrium)
\coordinate (d) at (intersection of s_1--s_2 and d_1--d_2);
%Intersection (after equilibrium)
\draw[dashed] (yaxis |- d) node[left] {$P'$} -| (xaxis -| d) node[below] {$B'$};
\fill[black] (d) circle (2pt);
\draw[->,thick] ([xshift=20, yshift=-20]c) -- ([xshift=20, yshift=-20]d); // <-- this is the arrow part I want to do
\end{tikzpicture}
\end{document}
5
  • this solution and the one above are all wonderful. thank you for your all your time!
    – ben
    Jun 14, 2014 at 9:21
  • I don't understand your first sentence. Can you elaborate a bit? Do you mean the transformation won't apply ?
    – percusse
    Jun 14, 2014 at 9:21
  • @percusse If I correctly understood the pgfmanual, a canvas transformation can move a shape in the contrary a coordinate tranformation can't. Did I missunderstood ?
    – Tarass
    Jun 14, 2014 at 9:33
  • @Tarass No no I just didn't understand the sentence. I think I get what you mean but curious about global operation part. You know curiosity kills the cat :)
    – percusse
    Jun 14, 2014 at 9:36
  • @percusse Please feel free to rephrase ma sentence, as you know both tikz and english better than me. I don't undersand the cat's story ;-)
    – Tarass
    Jun 14, 2014 at 9:43
6

Another way is to use orthogonal specifiers (via calc library)

\draw[->] ($(c)!-20pt!90:(d)$) -- ($(d)!20pt!90:(c)$);
4

This solution observes that you have used label d_1 and d_2 nodes twice for the blue lines because xshfit=20 and yshift=20 were used to draw the second blue line. If you are willing to change the second d_1 and d_2 into dd_1 and dd_2 and the coordinate (d) accordingly then one may use the relative coordinate to draw lines between blue lines B^d and B^{d'}.

\draw[->, black,] ($(d_1)!0.8!(d_2)$) -- ($(dd_1)!0.8!(dd_2)$); % decimal numbers are between [0 1]. 
\draw[<-, black,] ($(d_1)!0.3!(d_2)$) -- ($(dd_1)!0.3!(dd_2)$); % 

enter image description here

Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shadows,patterns,calc}

\begin{document}

\begin{tikzpicture}
%Axis
\draw [<->] (0,5) node (yaxis) [left] {$P$} -- (0,0) node[below left] {(0,0)} -- (5,0) node (xaxis) [below] {$B$};
%Title
\draw (3,5) node[above, xshift=-10] {Corporate Bonds};
%Supply
\draw[->, red] (1,1) coordinate (s_1) -- (4,4) coordinate (s_2) node[above right] {$B^{s}$};
%Demand
\draw[->, blue] (1,4) coordinate (d_1) -- (4,1) coordinate (d_2) node[below right] {$B^{d}$};
%Save Intersection (equilibrium)
\coordinate (c) at (intersection of s_1--s_2 and d_1--d_2);
%Intersection (equilibrium)
\draw[dashed] (yaxis |- c) node[left] {$P^e$} -| (xaxis -| c) node[below] {$B^e$};
\fill[black] (c) circle (2pt);
%Demand After
\draw[->, blue, xshift=20, yshift=20] (1,4) coordinate (dd_1) -- (4,1) coordinate (dd_2) node[below right] {$B^{d'}$};
%Save Intersection (after equilibrium)
\coordinate (d) at (intersection of s_1--s_2 and dd_1--dd_2);  % change dd_1 and dd_2
%Intersection (after equilibrium)
\draw[dashed] (yaxis |- d) node[left] {$P'$} -| (xaxis -| d) node[below] {$B'$};
\fill[black] (d) circle (2pt);
\draw[->, black,] ($(d_1)!0.8!(d_2)$) -- ($(dd_1)!0.8!(dd_2)$); % <-- this is the arrow part I want to do
\draw[<-, black,] ($(d_1)!0.3!(d_2)$) -- ($(dd_1)!0.3!(dd_2)$); % <-- this is the arrow part I want to do
\end{tikzpicture}

\end{document}
2
  • Your solution is blue line dependent, in particular, in that lines have to be same length. Take a look at my edit.
    – Tarass
    Jun 14, 2014 at 7:20
  • 1
    @Tarass -- I understand your point. Actually, I was ready to post your first solution, but you are fast :)- so I had to think other solution, independent of yours, and the parallel feature of blue lines inspired this feasible solution. Thanks for the comment.
    – Jesse
    Jun 14, 2014 at 7:33
0

Using the tzplot package:

enter image description here

\documentclass[tikz]{standalone}
    
\usepackage{tzplot}

\begin{document}

\begin{tikzpicture}
% Axis and Title
% \tzhelplines(5,5)
\tzaxes(5,5){$B$}[b]{$P$}[l]
\tznode(2.5,5){Corporate Bonds}[a]
\tzshoworigin{$O$}
% Supple and Demand
\tzcoors(1,1)(s_1)(4,4)(s_2)(1,4)(d_1)(4,1)(d_2);
\tzline"supply"(s_1)(s_2){$B^s$}[ar,red]
\tzline"demand"(d_1)(d_2){$B^d$}[br,blue]
% Demand After: <shift>
\tzline<20pt,20pt>"demand1"(d_1)(d_2){$B^{d'}$}[br,blue]
% Intersection (equilibrium)
\tzXpoint*{supply}{demand}(d)
\tzXpoint*{supply}{demand1}(d1)
% Projection
\tzproj(d){$B^e$}{$P^e$}
\tzproj(d1){$B'$}{$P'$}
% Arrows
\tzline[thick,->,tzshorten={0pt}{1.2pt}](d)(d1)
\tzcoor*($(d)!1.3cm!(d_2)$)(m){$m$}[-90]
\tzcoor*($(d1)-(d)+(m)$)(n){$n$}[0]
\tzline[thick,->,tzshorten={0pt}{1.2pt}](n)(m)
\end{tikzpicture}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .