带有断箭头连接的 Tikz 链

带有断箭头连接的 Tikz 链

我正在尝试编写一个相当长的工作流程图,因此会来回曲折。出于个人的审美偏好,我希望将一些连接箭头断开而不是笔直。

我使用链式结构,因为我想让代码尽可能简洁。它最终将进入 Beamer 演示,其中节点将一次显示一个。

我曾尝试更改链接,join=by |->但这会更改箭头本身而不是链接。

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning, calc, arrows, chains}

\begin{document}

% https://tex.stackexchange.com/questions/56427/how-to-evenly-space-out-nodes-or-in-tikz
\begin{tikzpicture}[
        start chain,
        node distance = 15mm,
        every node/.style = {inner sep = 2mm, on chain, join},
        every join/.style = {->},
    ]
    \node (A) {A};
    \node (B) {B};
    \node (C) {C};
    \node (D) {D};
    \node[continue chain=going below, join = by |->] (E) {E}; % would like the join to be U shaped rather than straight down
    \node[continue chain=going left] (F) {F};
    \node (G) {G};
    \node (H) {H};
    \node (I) {I};
    \node[continue chain=going below, align=center] (J) {J}; 
    \node[join = by -, inner sep = 0pt] {};
    \node[continue chain=going right] (K) {K}; % L shaped link preferably without intermediary node
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

也许这很有趣。可以使用选项修改 的路径jointo path但是,您需要joinevery node样式中删除,否则您将在节点之间得到两个箭头。一个来自 中的joinevery node一个来自附加join=by ...

为了使添加背面变得不那么繁琐join,请使用环境,或者(如下面的代码所示)使用库提供的scope简写。scopescopes

定位的方法K并不理想,我只是yshift在其中添加了一些负面的东西。

在此处输入图片描述

\documentclass[tikz, border=5mm]{standalone}

\usetikzlibrary{ chains, scopes} % added scopes library

\begin{document}

% https://tex.stackexchange.com/questions/56427/how-to-evenly-space-out-nodes-or-in-tikz
\begin{tikzpicture}[
        start chain,
        node distance = 15mm,
        every node/.style = {inner sep = 2mm, on chain}, % removed join
        every join/.style = {->},
    ]
    { [every node/.append style={join}] % shorthand for scope environment requires scopes library
    \node (A) {A};
    \node (B) {B};
    \node (C) {C};
    \node (D) {D};
    }

    \node[continue chain=going below,
          % define a custom to path to use for this join
          % when you use "join=by ..." an edge is created and "..." are passed as options to the edge
          join = by {to path={(\tikztostart) -- ++(1cm,0) |- (\tikztotarget)}}
          ] (E) {E}; 

    { [every node/.append style={join}]
    \node[continue chain=going left] (F) {F};
    \node (G) {G};
    \node (H) {H};
    \node (I) {I};
    \node[continue chain=going below, align=center] (J) {J}; 
    }

    \node[continue chain=going right,
          yshift=-15mm, % move node down manually
          join=by {to path={(\tikztostart) |- (\tikztotarget)}}] (K) {K}; 

    { [every node/.append style={join}]
    \node (I) {L};
    % etc
    }
\end{tikzpicture}

\end{document}

答案2

绝对不是最好的方法

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning, calc, arrows, chains}

\begin{document}

% https://tex.stackexchange.com/questions/56427/how-to-evenly-space-out-nodes-or-in-tikz
\begin{tikzpicture}[
        start chain,
        node distance = 15mm,
        every node/.style = {inner sep = 2mm, on chain, join},        
        every join/.style = {->},
    ]
    \node (A) {A};
    \node (B) {B};
    \node (C) {C};
    \node (D) {D};
    \node[continue chain=going below, join = by {white}] (E) {E}; % would like the join to be U shaped rather than straight down
    \node[continue chain=going left] (F) {F};
    \node (G) {G};
    \node (H) {H};
    \node (I) {I};
    \node[continue chain=going below, align=center] (J) {J}; 
    % \node[join = by -, inner sep = 0pt] {};
    \node[join= by {white}, inner sep = 0pt] {};
    \node[join= by {white}, continue chain=going right,] (K) {K}; % L shaped link preferably without intermediary node
    \draw[->, blue] (J.south) |- (K);
    \draw[->, blue] (D.east) |- ++(10mm,0) -- ($(E.east) + (10mm,0)$) -> (E.east);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容