保持两个节点之间的路径始终笔直

保持两个节点之间的路径始终笔直

在此mwe,我试图让节点之间的所有路径都是直角,但我无法做到,即使在此 SO 中看到多个问题之后,例如

    \documentclass[a4paper]{standalone}
    \usepackage{tikz}
    \usepackage{multirow,caption,subcaption}
    \usepackage{blindtext, forest,tikz}
    \usepackage[cache=false]{minted}
    \usetikzlibrary{positioning,arrows,trees}
    \usetikzlibrary{decorations.pathmorphing}
    \usetikzlibrary{decorations.markings}
    \usetikzlibrary{shadows.blur, shapes.arrows, shapes.geometric, shapes.misc}
    \begin{document}
    \tikzstyle{decision} = [diamond, draw,
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, text width=10em, text centered, rounded corners, minimum
    height=0em]
    \tikzstyle{line} = [draw, -latex', thick]
    \tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm, minimum height=2em]

    \begin{tikzpicture}
        \node [block, text width=14em](init) {User Interface};
        \node [block,node distance=4em, text width=5em](EF) at(-2.2,-1.5) {\small{Explanation Facility}};
        \node [block, right of= EF, node distance=7em, text width=5em](ts)  {\small{Trace Facilities}};
        \node [block, below of=init, node distance=8em, text width=14em](ie) {Inference Engine};
        \node [block, below of=ie, node distance=4em, text width=14em](kb) {\textit{Knowledge Base}};
        \node [above of=init, node distance=.5cm](est) {\textbf{Expert System}};
        \path [line] ([xshift=2em]init)--([xshift=2em]EF);
        \path [line] (init)--(ts);
        \path [line, transform canvas={xshift=4em}] (init)--(ie);
    \end{tikzpicture}
    \end{document}

我目前得到的是: 在此处输入图片描述

答案1

这会产生这样的路径。请注意,\tikzstyle已被弃用。

\documentclass[a4paper]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\begin{document}
\tikzset{decision/.style={diamond, draw,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt},
block/.style={rectangle, draw, text width=10em, text centered, rounded corners, minimum
height=0em},
line/.style={draw, -latex', thick},
cloud/.style={draw, ellipse,fill=red!20, node distance=3cm, minimum
height=2em}}

\begin{tikzpicture}
    \node [block, text width=14em](init) {User Interface};
    \node [block,node distance=4em, text width=5em,font=\small](EF) at(-2.2,-1.5) {Explanation Facility};
    \node [block, right of= EF, node distance=7em, text width=5em,font=\small](ts)  {Trace Facilities};
    \node [block, below of=init, node distance=8em, text width=14em](ie) {Inference Engine};
    \node [block, below of=ie, node distance=4em, text width=14em,font=\itshape](kb) {Knowledge Base};
    \node [above of=init, node distance=.5cm,font=\bfseries](est) {Expert System};
    \path [line] (init.south-|EF)--(EF);
    \path [line] (init.south-|ts)--(ts);
    \path [line] ([xshift=-2em]init.south east)--([xshift=-2em]init.south
    east|-ie.north);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容