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 hv
和to path vh
,因為使用|
is 鍵名稱以錯誤結尾。
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