Tikz - 绘制 Shift 箭头

Tikz - 绘制 Shift 箭头

我试图绘制从一个点到另一个点的移位箭头,但似乎不起作用。这是我的代码:

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

以下是图片:

在此处输入图片描述

我已经让箭头指向正确的方向,但我希望箭头从两个交叉点移开,以便读者可以更好地看到它。但是,当我使用“xshift”或“yshift”时,它甚至不会移动箭头;箭头只是停留在原处。

答案1

您不能通过全局操作来移动或旋转形状,您必须为每个形状或通过画布变换明确指定它。

编辑 :

另一种解决方案是使用:

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

只有1.5一个因素可以向右移动箭头(如果 >0)和向左移动箭头(如果 <0)。

在此处输入图片描述

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

答案2

另一种方法是使用正交说明符(通过calc库)

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

答案3

此解决方案观察到,您已两次使用标签d_1d_2节点来绘制蓝线,因为xshfit=20yshift=20用于绘制第二条蓝线。如果您愿意将第二个d_1和更改d_2dd_1和,并相应地更改坐标 (d),那么可以使用相对坐标在蓝线和dd_2之间绘制线条。B^dB^{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)$); % 

在此处输入图片描述

代码

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

答案4

使用tzplot包裹:

在此处输入图片描述

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

相关内容