路径起始节点错误

路径起始节点错误

出现一个奇怪的错误,即从某个节点开始的任何路径都从错误的位置开始。红色路径在代码中是相同的。左侧的图像是我期望的,但右侧的图像是我得到的。有什么想法导致这种情况的吗?

在此处输入图片描述

右图代码(大量裁剪图片,因此有很多内容未显示):

\documentclass{article}

\usepackage{tikz}
\pagestyle{empty}

\begin{document}

%\input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, 
                        draw, 
                        text centered, 
                        minimum height=3em 
                      ]
\tikzstyle{test}    = [ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 0pt,
                        text width = 7em,
                        text centered
                      ]
\tikzstyle{action}  = [ rectangle, draw,
                        text width=8em,
                        inner sep = 5pt, 
                        minimum height=5em
                      ]
\tikzstyle{data}    = [ trapezium, 
                        draw, 
                        trapezium left angle=60, 
                        trapezium right angle=120pt,
                        minimum height = 6em, 
                        text width = 5em
                       ]
\tikzstyle{line}    = [ draw, -triangle 45 ]


\begin{tikzpicture}[align = flush center, font = \small]
    % Place nodes
    \matrix [row sep = 1.2em] (mtrx)
    {
    \node [state] (a) {Lorem ipsum}; \\

    \node [test] (b) { dolor sit amet, con}; \\

    \node [test] (c) {sectetur adipiscing elit. In bibendu}; \\

    \node [test] (d) {m ante laoreet ante semper convallis. Pellentesque habi}; \\

    \node [action] (e) {tant morbi tristique senectus et netus et malesuada fames ac turpis eg}; \\

    \node [test] (f) {estas. Pellentesque vitae dia}; &    
    \node [test] (g) {m magna. Pellent}; \\

    \node [test] (h) {esque placerat sa}; \\

    \node [action] (i) {pien sed nisl faucibus tempor. Nullam nec quam nulla, se}; &
    \node [action] (j) {d pulvinar lacus. Aenean sit amet tellus erat, non temp}; &
    \node [action] (k) {or justo. Phasellus ege}; \\

    \node [test] (l) {stas iaculis nisi vel ve}; &
    \node [test] (m) {stibulum.Mauris id fa}; \\

    \node [state] (n) {cilisis massa. C}; &
    \node [state] (o) {urabitur feugiat v}; \\

    & 
    &
    \node [state, yshift=-2em] (p) {estibulum convallis \\ . Nulla dictum tinc}; \\
    };

    % Draw edges
    \path [line] (a) -- (b);

    \path [line] (b.east) -- node [above,very near start] {Yes} +(8.5,0) |- ( $(k)!0.85!(p)$ );
    \path [line] (b.south) -- node [right] {No} (c);

    \path [line] (c.south) -- node [right] {Yes} (d);    
    \path [line] (c.east) -| node [above,very near start] {No} (g);

    \path [line] (d.south) -- node [right] {Yes} (e);
    \path [line] (d.west) -- node [above] {No}  +(-1,0) |- coordinate[midway] (e) (f);

    \path [line, red] (e) -- (f);    
    \path [line] (g) -- node [right] {Yes} (j);

    \path [line] (k) -- (p);
\end{tikzpicture}

\end{document}

左图代码:

\documentclass{article}

\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\usetikzlibrary{shapes, arrows, calc, positioning}

% Define block styles
\tikzstyle{state}   = [ rounded rectangle, draw, 
                        text centered, 
                        minimum height=3em 
                      ]
\tikzstyle{test}    = [ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 0pt,
                        text width = 7em,
                        text centered
                      ]
\tikzstyle{action}  = [ rectangle, draw,
                        text width=8em,
                        inner sep = 5pt, 
                        minimum height=5em
                      ]

\tikzstyle{line}    = [ draw, -triangle 45 ]

\begin{tikzpicture}[align = flush center, font = \small]
    % Place nodes
    \matrix[ row sep=1.2em] (mtrx) 
    {
    \node [test] (f) {fLorem ipsum dolor sit amet}; \\

    \node [test] (h) {hLorem ipsum dolo}; \\

    \node [action] (i) {iLorem ipsum dolor sit amet, consectetur adipiscing elit.}; \\

    \node [test] (l) {lLorem ipsum dolor};\\
    };

    \path [line,red] (i) -- (l);
    \path [line] (h.west) -- node [above] {No}  +(-1,0) |- coordinate[midway] (i) (l);
\end{tikzpicture}


\end{document}

我真的不明白我为什么会犯这个错误。

答案1

不要e对不同的节点或坐标使用相同的名称(在您的 MWE 中)!

看看这段代码:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  % first example
  \node (a) at (0,0) {A};
  \node (b) at (1,1) {B};
  \draw (a) -- node [pos=.5] (c) {C} (b);
  \draw[blue] (a) to[bend left] (b); 

  % second example
  \node (d) at (2,0) {D};
  \node (e) at (3,1) {E};
  \draw (d) -- node [pos=.5] (d) {D} (e);
  \draw[red] (d) to[bend left] (e); 
\end{tikzpicture}
\end{document}

在此处输入图片描述

第一个例子使用了三个不同的名称,因此蓝线是正确的。

第二个示例使用了d两个不同节点的名称,因此红线不正确。

编辑:

当你写:

\draw (a) -- coordinate[midway] (m) (b);

你会触发两个不同的动作:

  1. a和之间的路径的绘制b\draw (a) -- (b);

  2. 在位置和m之间路径上的坐标定义(相当于)。abmidwaymidwaypos=.5

相关内容