-|- 箭头指向错误的方向

-|- 箭头指向错误的方向

问题

箭头-|-与左侧的另一个节点相交。我希望它指向东,然后指向北,然后指向西。我如何更改此箭头的方向?我查看了蒂克兹Tikz-cd手册,但我一直在努力解决这个问题。

请注意,箭头起始于store: d并终止于[for] search new (x)。箭头如下所示: 在此处输入图片描述


代码

问题出在 的下\graph [use existing nodes]。的宏位于 下,下面是我隔离问题的代码的简化版本:nM -> [dashed, vh path] nK; nN2 -> [dashed, -|-] nF;\matrix[row sep=5mm, column sep=5mm]-|-\begin{tikzpicture}-|-/.style=...

%---[ load packages ] - document format
\documentclass[10pt]{extarticle}
\usepackage{extsizes}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}

%---[ load packages ] - page format
\usepackage{geometry}
\usepackage{titling, titlesec, fancyhdr}
\geometry{
    a4paper,
    total={170mm,257mm},
    textwidth=420pt,
    top=38mm,
    bottom=38mm,
}

%---[ load packages ] - graphics presentation
\usepackage{tikz, pgf}
\usetikzlibrary {positioning, graphs, arrows.meta}
\tikzset{every picture/.style={/utils/exec={\ttfamily}}}

%---[ document ]
\begin{document}
%---[D-graphics] block
% -------------------------------------------------------------------------------------------[S]
\begin{figure}[H]
    \begin{center}
        \begin{tikzpicture}[nonterminal/.style={rectangle, minimum size=4mm, rounded corners=1mm, fill=grey!10},
                            >={Stealth[round]}, thick, black!90,
                            every new ->/.style={shorten >=1pt},
                            bend left/.style={to path={-| (\tikztotarget)}},
                            bend right/.style={to path={|- (\tikztotarget)}},
                            hv path/.style={to path={-| (\tikztotarget)}},
                            vh path/.style={to path={|- (\tikztotarget)}},
                            -|-/.style={to path={
                                (\tikztostart.east) -| ($(100.east)+(0.5,0)$) |- (\tikztotarget.east)}},
                                graphs/every graph/.style={edges=rounded corners}
            ],
            \matrix[row sep=5mm, column sep=5mm] {
                % row 01
                \node (nA) [anchor=west, nonterminal, fill=black!90, text=white, minimum width=2cm] {begin}; & & & & \\
                % row 02
                \node (nB) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {instruct}; & & & & \\
                % row 03
                \node (nC) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {start}; & & & & \\
                % row 04
                & \node (nD) [anchor=west, nonterminal] {inputs}; & & & \\
                % row 05
                & \node (nE) [anchor=west, nonterminal] {$d = sum - x$}; & & & \\
                % row 06
                & \node (nF) [anchor=west, nonterminal] {[for] search new (x)}; & & & \\
                % row 07
                & \node (nG) [anchor=west, nonterminal] {[for] search old (y)}; & & & \\
                % row 08
                & & \node (nH) [anchor=west, nonterminal, fill=blue!30!green!35] {[if]}; & & \\
                % row 09
                & & & \node (nI) [anchor=west, nonterminal] {$x \text{!=} y$}; & \\
                % row 10
                & & & \node (nJ) [anchor=west, nonterminal] {$x \text{==} y$}; & \node (nJ2) [anchor=west, nonterminal] {$d = sum - y$}; \\
                % row 11
                & \node (nK) [anchor=west, nonterminal] {[for] search old (z)}; & & & \\
                % row 12
                & & \node (nL) [anchor=west, nonterminal, fill=blue!30!green!35] {[if]}; & & \\
                % row 13
                & & & \node (nM) [anchor=west, nonterminal] {$z \text{!=} d$}; & \\
                % row 14
                & & & \node (nN) [anchor=west, nonterminal] {$z \text{==} d$}; & \node (nN2) [anchor=west, nonterminal] {store: $d$}; \\
                % row 15
                \node (nO) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {print}; & & & & \\
                % row 16
                \node (nP) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {update}; & & & & \\
                % row 17
                & \node (nQ) [anchor=west, nonterminal] {[while] user input y/n}; & & & \\
                % row 18
                & & \node (nR) [anchor=west, nonterminal] {yes}; & \node (nR2) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {start}; & \node (nR3) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {print}; \\
                % row 19
                & & \node (nS) [anchor=west, nonterminal] {no}; & \node (nS2) [anchor=west, nonterminal] {terminate}; & \\
                % row 20
                \node (nT) [anchor=west, nonterminal, fill=black!90, text=white, minimum width=2cm] {end}; & & & & \\
            };
            \graph [use existing nodes] {
                % begin
                nA -> nB;
                % instruct function
                nB -> nC;
                % start function
                nC -> [distance=2mm, vh path] {nD, nE, nF, nG, nK}; nF -> nG -> nK;
                nG -> [vh path] nH;
                nH -> [distance=2mm, vh path] {nI, nJ}; nJ -> nJ2;
                nI -> [dashed, vh path] nG;
                nK -> [vh path] nL;
                nL -> [distance=2mm, vh path] {nM, nN}; nN -> nN2;
                nM -> [dashed, vh path] nK; nN2 -> [dashed, -|-] nF;
                % print function
                nC -> nO;
                % update function
                nO -> nP;
                nP -> [vh path] nQ;
                nQ -> [distance=2mm, vh path] {nR, nS}; nR -> nR2 -> nR3; nS -> nS2;
                nR3 -> [dashed, vh path] nQ;
                % end
                nP -> nT;
            };
        \end{tikzpicture}
    \end{center}
\end{figure}
% -------------------------------------------------------------------------------------------[E]
\end{document}

答案1

删除100.east并修改-|- style——只使用一条延伸线east,然后0.5,0向上连接目标似乎就足够了——还删除了H图中的选项——因为灰色也造成了错误,因此black!10改用

在此处输入图片描述

\documentclass[10pt]{extarticle}
\usepackage{extsizes}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}

%---[ load packages ] - page format
\usepackage{geometry}
\usepackage{titling, titlesec, fancyhdr}
\geometry{
    a4paper,
    total={170mm,257mm},
    textwidth=420pt,
    top=38mm,
    bottom=38mm,
}

%---[ load packages ] - graphics presentation
\usepackage{tikz, pgf}
\usetikzlibrary {positioning, graphs, arrows.meta, calc}
\tikzset{every picture/.style={/utils/exec={\ttfamily}}}

%---[ document ]
\begin{document}
%---[D-graphics] block
% -------------------------------------------------------------------------------------------[S]
\begin{figure}
    \begin{center}
        \begin{tikzpicture}[nonterminal/.style={rectangle, minimum size=4mm, rounded corners=1mm, fill=black!10},
                            >={Stealth[round]}, thick, black!90,
                            every new ->/.style={shorten >=1pt},
                            bend left/.style={to path={-| (\tikztotarget)}},
                            bend right/.style={to path={|- (\tikztotarget)}},
                            hv path/.style={to path={-| (\tikztotarget)}},
                            vh path/.style={to path={|- (\tikztotarget)}},
                            -|-/.style={to path={
                                (\tikztostart.east)-- ++(0.5,0) |- (\tikztotarget.east)}},
                                graphs/every graph/.style={edges=rounded corners}
            ],
            \matrix[row sep=5mm, column sep=5mm] {
                % row 01
                \node (nA) [anchor=west, nonterminal, fill=black!90, text=white, minimum width=2cm] {begin}; & & & & \\
                % row 02
                \node (nB) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {instruct}; & & & & \\
                % row 03
                \node (nC) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {start}; & & & & \\
                % row 04
                & \node (nD) [anchor=west, nonterminal] {inputs}; & & & \\
                % row 05
                & \node (nE) [anchor=west, nonterminal] {$d = sum - x$}; & & & \\
                % row 06
                & \node (nF) [anchor=west, nonterminal] {[for] search new (x)}; & & & \\
                % row 07
                & \node (nG) [anchor=west, nonterminal] {[for] search old (y)}; & & & \\
                % row 08
                & & \node (nH) [anchor=west, nonterminal, fill=blue!30!green!35] {[if]}; & & \\
                % row 09
                & & & \node (nI) [anchor=west, nonterminal] {$x$}; & \\
                % row 10
                & & & \node (nJ) [anchor=west, nonterminal] {$x $}; & \node (nJ2) [anchor=west, nonterminal] {$d = sum - y$}; \\
                % row 11
                & \node (nK) [anchor=west, nonterminal] {[for] search old (z)}; & & & \\
                % row 12
                & & \node (nL) [anchor=west, nonterminal, fill=blue!30!green!35] {[if]}; & & \\
                % row 13
                & & & \node (nM) [anchor=west, nonterminal] {$z$}; & \\
                % row 14
                & & & \node (nN) [anchor=west, nonterminal] {$z$}; & \node (nN2) [anchor=west, nonterminal] {store: $d$}; \\
                % row 15
                \node (nO) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {print}; & & & & \\
                % row 16
                \node (nP) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {update}; & & & & \\
                % row 17
                & \node (nQ) [anchor=west, nonterminal] {[while] user input y/n}; & & & \\
                % row 18
                & & \node (nR) [anchor=west, nonterminal] {yes}; & \node (nR2) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {start}; & \node (nR3) [anchor=west, nonterminal, minimum width=2cm, draw=black!90] {print}; \\
                % row 19
                & & \node (nS) [anchor=west, nonterminal] {no}; & \node (nS2) [anchor=west, nonterminal] {terminate}; & \\
                % row 20
                \node (nT) [anchor=west, nonterminal, fill=black!90, text=white, minimum width=2cm] {end}; & & & & \\
            };
            \graph [use existing nodes] {
                % begin
                nA -> nB;
                % instruct function
                nB -> nC;
                % start function
                nC -> [distance=2mm, vh path] {nD, nE, nF, nG, nK}; nF -> nG -> nK;
                nG -> [vh path] nH;
                nH -> [distance=2mm, vh path] {nI, nJ}; nJ -> nJ2;
                nI -> [dashed, vh path] nG;
                nK -> [vh path] nL;
                nL -> [distance=2mm, vh path] {nM, nN}; nN -> nN2;
                nM -> [dashed, vh path] nK; nN2 -> [dashed, -|-] nF;
                % print function
                nC -> nO;
                % update function
                nO -> nP;
                nP -> [vh path] nQ;
                nQ -> [distance=2mm, vh path] {nR, nS}; nR -> nR2 -> nR3; nS -> nS2;
                nR3 -> [dashed, vh path] nQ;
                % end
                nP -> nT;
            };
        \end{tikzpicture}
    \end{center}
\end{figure}
% -------------------------------------------------------------------------------------------[E]
\end{document}

相关内容