在 tikz 框图中添加箭头

在 tikz 框图中添加箭头

如何添加这一行?

在此处输入图片描述 当前代码:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{fp, tikz}
\usetikzlibrary{arrows,shapes,backgrounds,patterns,fadings,matrix,arrows,calc,
    intersections,decorations.markings,
    positioning,external,arrows.meta}
\tikzset{
    block/.style = {draw, rectangle,
        minimum height=1cm,
        minimum width=2cm},
    input/.style = {coordinate,node distance=1cm},
    output/.style = {coordinate,node distance=6cm},
    arrow/.style={draw, -latex,node distance=2cm},
    pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
    sum/.style = {draw, circle, node distance=1cm},
}
\begin{document}


   \begin{tikzpicture}[auto, >=latex', transform shape,font={\sffamily \small}] 

    \node [draw=black,
    minimum width=1.6cm,
    minimum height=1.2cm, 
    align=center]   (1) {1};
    
    \node [draw=black,
    minimum width=1.6cm,
    minimum height=1.2cm, 
    align=center,
    right=0.6cm of 1]   (2) {2};
    
    \node [draw=black,
    minimum width=1.6cm,
    minimum height=1.2cm, 
    align=center,
    right=0.6cm of 2]   (3) {3}; 

    \draw[->,line width=0.25mm] (1.east) -- (2.west);
    \draw[->,line width=0.25mm] (2.east) -- (3.west);
    
    
    \end{tikzpicture}
\end{document}

我的尝试:\draw[->,line width=0.25mm] ($(1)!0.5!(2)$) --++ (0,1cm) -| (3);

答案1

我们可以|-先垂直移动,然后水平移动从 A 点到 B 点。(或者-|先水平移动,然后垂直移动。)

我们也可以将其用作2.east粗略标记。如果可以的话([yshift=1cm]2.east),第二点最终会位于 的最右侧上方2。因此我们可以说

$(1)!.5!(2)$ |- (yshift=1cm]2.east

第一部分。现在我们需要再多走一点,然后向下,再穿过到稍高于 的点。让我们取和锚点3.west之间的中点, 。westnorth west($(3.west)!.5!(3.north west)$)

-|我们可以通过手动调整或其他方式来改变方向|-,但如果没有必要,为什么要这么麻烦呢?

ext.paths.ortho库允许我们使用增强的语法来指定路径。在我们的例子中,-|-它指示tikz在两点之间先水平移动,然后垂直移动,然后水平移动。

\draw[->,line width=0.25mm] ($(1.east)!0.5!(2.west)$) |- ([yshift=1cm]2.east) -|- ($(3.west)!.5!(3.north west)$);

转向箭头 向上 向下

完整代码:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{fp, tikz}
\usetikzlibrary{arrows,shapes,backgrounds,patterns,fadings,matrix,arrows,calc,
    intersections,decorations.markings,
    positioning,external,arrows.meta,ext.paths.ortho}
\tikzset{
    block/.style = {draw, rectangle,
        minimum height=1cm,
        minimum width=2cm},
    input/.style = {coordinate,node distance=1cm},
    output/.style = {coordinate,node distance=6cm},
    arrow/.style={draw, -latex,node distance=2cm},
    pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
    sum/.style = {draw, circle, node distance=1cm},
}
\begin{document}


   \begin{tikzpicture}[auto, >=latex', transform shape,font={\sffamily \small}] 

    \node [draw=black,
    minimum width=1.6cm,
    minimum height=1.2cm, 
    align=center]   (1) {1};
    
    \node [draw=black,
    minimum width=1.6cm,
    minimum height=1.2cm, 
    align=center,
    right=0.6cm of 1]   (2) {2};
    
    \node [draw=black,
    minimum width=1.6cm,
    minimum height=1.2cm, 
    align=center,
    right=0.6cm of 2]   (3) {3}; 

    \draw[->,line width=0.25mm] (1.east) -- (2.west);
    \draw[->,line width=0.25mm] (2.east) -- (3.west);
    \draw[->,line width=0.25mm] ($(1.east)!0.5!(2.west)$) |- ([yshift=1cm]2.east) -|- ($(3.west)!.5!(3.north west)$);
    
    \end{tikzpicture}
\end{document}

答案2

您可以在 (1) 到 (2) 的线段上命名一个坐标,就像命名一个节点一样。线的中点是默认值。然后您可以从那里绘制新的箭头。

该点(3.160)位于节点边界上(3),角度为 160 度(略高于west该角度为 180 度)。您也可以将其用作([yshift=3mm]3.west)最终点,该点位于中心上方 3 毫米处。

在此处输入图片描述

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning, arrows}

\tikzset{
    block/.style = {draw, rectangle, minimum height=1.2cm, minimum width=1.6cm}
}

\begin{document}

   \begin{tikzpicture}[>=latex',font={\sffamily\small}, node distance=.6cm] 

    \node [block] (1) {1};
    \node [block, right=of 1] (2) {2};
    \node [block, right=of 2] (3) {3}; 

    \draw[->,line width=0.25mm] (1) --coordinate(M1) (2);
    \draw[->,line width=0.25mm] (2) --coordinate(M2) (3);
    \draw[->,line width=0.25mm] (M1) |- ([yshift=9mm]M2) |- (3.160);

    \end{tikzpicture}

\end{document}

答案3

基于我的答案关于你之前的问题,即通过使用chainsext.paths.ortho库。我的 MWE 只关注你的问题,所以与你的 MWE 相比,它要短得多,然而顺便说一句,它还展示了如何更有效地绘制块方案:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                ext.paths.ortho,    % defined in the tikz-ext package
                positioning,
                }

\begin{document}
    \begin{tikzpicture}[
node distance = 4mm and 6mm,
  start chain = going right,
   arr/.style = {-{Straight Barb[scale=0.8]}, semithick},
   box/.style = {% default is rectangle
                 draw, minimum height = 10mm, minimum width=20mm,
                 on chain, join=by arr}
                        ]
\foreach \i in {1,2,3}
    \node [box] (n\i) {\i};  % nodes are in chain
%
\path       (n1) -- coordinate  (aux) (n2);   % defined coordinate between nodes n1 and n2
\draw[arr]  (aux)  |- ([yshift=5mm] n2.north) % first part of arrow  
                  -|- [distance=-3mm] ([yshift=3mm] n3.west); % second part of arrow
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案4

像这样:

在此处输入图片描述

代码(仅限tikz-无库):

\documentclass{article}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \draw[line width=3pt] (0,0) node[minimum height=2cm,minimum width=3cm,draw] (1) {\Huge \bfseries 1};
        \draw[line width=3pt] (5,0) node[minimum height=2cm,minimum width=3cm,draw] (2) {\Huge \bfseries 2};
        \draw[line width=3pt] (10,0) node[minimum height=2cm,minimum width=3cm,draw] (3) {\Huge \bfseries 3};       
        \draw[-latex,line width=3pt] (1)  -- (2);
        \draw[-latex,line width=3pt] (2) -- (3);
        \draw[-latex,line width=3pt] (2.5,0)--(2.5,2)--(7.5,2)--(7.5,.5)--(8.5,.5);     
    \end{tikzpicture}
\end{document}

相关内容