Tikz 箭头不显示

Tikz 箭头不显示

MWE 如下(我正在使用 ConTeXt)

\usemodule[tikz]
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}
\usetikzlibrary{calc}
\tikzset{arrow/.style={-stealth, thick, draw=black!70!white}}
\starttext
\starttikzpicture[ampersand replacement=\&]
% \draw[help lines](0,-5) grid (10,5);  
    \node[rectangle, rounded corners, draw, fill=white!90!black, minimum height=1cm] at (3,0) (S) {SSS};   
    \node[rectangle, rounded corners, draw, fill=white!90!black, minimum height=1cm] at (3,3) (C) {CCC};    
    \node[rectangle, rounded corners, draw, fill=white!90!black, minimum height=1cm] at (6,1.5) (I) {III};    
    \node[rectangle, rounded corners, draw, fill=white!90!black, minimum height=1cm] at (10,1.5) (P) {PPP};
    
    \path[arrow]
    (S) edge (I.south west)
    (C) edge (I.north west)
    (I) edge (P)
    (C) -- (10,3) -|  (P.north)
    (S) -- (10,0) -|  (P.south)
    ;
\stoptikzpicture
\stoptext

我的目的是获取从 CCC 到 PPP 的路径末端的箭头(在 PPP 的北边),但它没有显示。请帮忙。谢谢。

答案1

箭头仅放置在路径的第一个和最后一个子路径上,请参阅https://tikz.dev/tikz-arrows#sec-16.2

在您的示例中(C) -- (10,3) -| (P.north),和(S) -- (10,0) -| (P.south)是两个子路径(由移动到路径操作分隔),因此箭头仅添加到(S) -- (10,0) -| (P.south)

您不需要将其拆分为多条路径,而是可以继续使用edge将多个箭头添加到一条路径,并使用一些额外的选项:

(node a) edge[to path={-| (\tikztotarget)}] (node b)

参见@Scz 的回答Tikz 节点之间的直角边 | TeX-SX#48397

完整改编的示例:

  • 箭头颜色与线条颜色相同,使用-{Stealth[black!70]}加载arrows.meta的库。
  • 新样式的键名为to path hvto path vh,因为使用|这个键名会导致错误。ConTeXt
    将 catcode 从|12(其他)设置为 13(活动),我推断这是原因。我从来都不是 ConTeXt 的普通用户,我只是绕过它。另请参阅ConTeXt 中哪些符号需要转义?| TeX-SX#48933
    更新:这可行但是失去了表现力:to path -\|/.style={...}
% !TeX TS-program = context %.tex
\usemodule[tikz]
\usetikzlibrary{arrows.meta, calc, positioning, shapes}
\tikzset{
  arrow/.style={-{Stealth[black!70]}, thick, draw=black!70},
  % based on https://tex.stackexchange.com/a/250515
  to path hv/.style={to path={-| (\tikztotarget)}},
  to path vh/.style={to path={|- (\tikztotarget)}}
}
\starttext
\starttikzpicture[ampersand replacement=\&]
% \draw[help lines](0,-5) grid (10,5);
    \node[rectangle, rounded corners, draw, fill=white!90!black, minimum height=1cm] at (3,0) (S) {SSS};
    \node[rectangle, rounded corners, draw, fill=white!90!black, minimum height=1cm] at (3,3) (C) {CCC};
    \node[rectangle, rounded corners, draw, fill=white!90!black, minimum height=1cm] at (6,1.5) (I) {III};
    \node[rectangle, rounded corners, draw, fill=white!90!black, minimum height=1cm] at (10,1.5) (P) {PPP};

    \path[arrow]
      (S) edge (I.south west)
      (C) edge (I.north west)
      (I) edge (P)
      (C) edge[to path hv] (P.north)
      (S) edge[to path hv] (P.south)
    ;
\stoptikzpicture
\stoptext

在此处输入图片描述

相关内容