如何使用 tikz 库改变箭头指向方向(在本例中为向右)。
我有以下代码,
\documentclass{article}
\usepackage{filecontents}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc,arrows,arrows.meta}
\tikzset{block/.style={draw,thick,text width=2cm,minimum height=1cm,align=center},
line/.style={-latex}
}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}[>=stealth]
%coordinates
\coordinate (orig) at (0,0);
\coordinate (LLD) at (4,0);
\coordinate (AroneA) at (-7/2,11/2);
\coordinate (ArtwoA) at (-7/2,5);
\coordinate (ArthrA) at (-1/2,9/2);
\coordinate (LLA) at (1,4);
\coordinate (LLB) at (5,4);
\coordinate (LLC) at (9,4);
\coordinate (AroneC) at (26/2,11/2);
\coordinate (ArtwoC) at (26/2,5);
\coordinate (ArthrC) at (25/2,9/2);
\coordinate (conCBD) at (25/2,10/2);
\coordinate (conCB) at (25/2,6/2);
\coordinate (coCBD) at (11,6);
%nodes
\node[draw, minimum width=2cm, minimum height=2cm, anchor=south west, text width=2cm, align=center] (A) at (LLA) {A};
\node[draw, minimum width=2cm, minimum height=2cm, anchor=south west, text width=2cm, align=center] (B) at (LLB) {B};
\node[draw, minimum width=3cm, minimum height=2cm, anchor=south west, text width=2cm, align=center] (C) at (LLC) {C};
%edges
\draw[->] (AroneA) -- node[above]{\textit{x}} ($(A.180) + (0,1/2)$);
\draw[->] (ArtwoA) -- node[above]{\textit{y}} (A.182);
\draw[->] (A.0) -- node[above] {$x_d$} (B.180);
\draw[->] (B.0) -- node[above] {$y_d$} (C.180);
\draw[->] (C.0) -- node[above, pos=0.4]{Y} (ArtwoC);
\path[fill] (conCBD) circle[radius=1pt];
\path[-{Straight Barb[angle'=60,scale=4]}] (conCBD) -- (conCB) -| ($(B.180) + (-1,-0.6)$) -| ($(B.180) + (-0.1,-0.8)$);
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
答案1
相对定位是 tikz 的一个非常好的功能。绝对定位可能相当困难,而且更容易出错(观察下面x
和y
图像中的水平线)。通常,最好使用相对定位或节点来绘制这种图表matrix
。对于反向箭头,我使用了\draw [<-] (B.210) -| ++(-.6,-1) -| ([xshift=.5cm] C.east) node[above]{$Y$};
。
\documentclass{article}
\usepackage{filecontents}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc,arrows,arrows.meta}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[>=stealth,blk/.style={draw, minimum width=2cm, minimum height=2cm}]
\node (y) {$y$};
\node (x) [above=2pt of y]{$x$};
\node (A) [right=of y,blk]{A};
\node (B) [right=of A,blk]{B};
\node (C) [right=of B,blk,minimum width=3cm]{C};
\draw [->] (y)--(A);
\draw [->] (x)--(A.west|-x);
\draw [->] (A)--node[above]{$x_d$}(B);
\draw [->] (B)--node[above]{$y_d$}(C);
\draw [->] (C.east)--++(1,0);
\draw [<-] (B.210) -| ++(-.6,-1) -| ([xshift=.5cm]C.east)node[above]{$Y$};
\end{tikzpicture}
\end{figure}
\end{document}