TikZ 令人困惑的路径方向

TikZ 令人困惑的路径方向

TikZ 倒箭头<code>在此处输入代码</code>

这是对问题的后续 使用 TikZ 复制 Knuth 书中的简单图表我很幸运地收到了各种有用且丰富的答案,对此我深表感谢。这个问题对应于使用 TikZ 绘制的图表,后来我需要修改它,并面临一个看似简单的箭头/路径方向问题,如附图所示。我只是申请了简单的直觉绘制从“增加 d”到“除以 d”的箭头,但是方向显然是错误的!

\documentclass{article}
\usepackage{tikz} % For drawing circles around numbers
\usetikzlibrary{shapes,arrows,positioning}

\begin{document}
\tikzset{
decision/.style = {draw, text width=6.0em, text badly centered, node distance=3cm, minimum height=2.0em},
block/.style = {rectangle, draw,text width=6.0em, text centered, rounded corners=2ex, minimum height=2.0em},
line/.style = {draw, -latex'},
cloud/.style = {draw, ellipse, node distance=3cm, minimum height=2em}
    }

\begin{figure}[H] 
\centering 
\begin{tikzpicture}[node distance = 2cm, auto] 
    % Place nodes
    \coordinate (a) at (0,0);
    \node [decision,below = 0.6cm of a, minimum height=2.5em] (init) {Initialize $(d = 2)$};
    \node [block, below = 0.8cm of init] (trivial) {$N = 1$?};
    \node [decision, above right = .15cm and 0.8cm of trivial] (divide) {Divide by $d$};
    \node [decision, below  = 0.8cm of divide] (factorFound) {Factor found};
    \node [block, below right = .15cm and 0.8cm of divide, node distance=3cm] (zeroRem){Zero remainder?};
    \node [decision, above = 1.25cm of zeroRem] (increase) {Increase $d$};
    \node [block, right = 0.8cm of zeroRem, node distance=3cm] (lowQuot){Low quotient?};
    \node [decision, below = 0.8cm of lowQuot] (prime) {$N$ is prime};
    % Draw edges
    \path [line] (a) -- (init);
    \path [line] (init) -- (trivial);
    \path [line] (trivial.10) -- node[midway,above=.5ex] {No}(divide.190);
    \path [line] (divide.-10) -- (zeroRem.175);
    \path [line] (zeroRem) -- node {No}(lowQuot);
    \path [line] (zeroRem.185) -- node {Yes}(factorFound.10);
    \path [line] (factorFound.170) -- (trivial.-10);
    \path [line] (lowQuot) -- node {Yes}(prime);
    \path [line,rounded corners=5ex] (lowQuot) -- ++(0, 1.96cm) node[right, near start] {No} -- (increase.east);
    \path [line,rounded corners=5ex] (increase) -| (divide.north); % here is the problem!
    \path [line] (trivial.south) -- node {Yes} +(0,-0.8cm);
    \path [line] (prime.south) -- +(0,-0.6cm);
    \end{tikzpicture} 
    \caption{Trial division flowchart as mentioned in \cite{Knuth 2004}.} 
    \label{Figure:TrialDivFlowChart} 
\end{figure}
\end{document}

答案1

这个问题的答案就是 percusse 在评论中建议的:“拐角半径太大”。将半径减小到 4ex 解决了问题。

相关内容