如果你使用的是tikzv3.0

如果你使用的是tikzv3.0

我正在尝试做一些非常简单的事情,但到目前为止还没有找到答案。我有一个流程图,我想在环境中绘制直角的直箭头而不是“弯曲”箭头matrix。这是我拥有的代码,我只需要一种方法来将左侧的弯曲箭头替换为像右边那样的直角弯曲的直箭头:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}

\begin{document}

% Define block styles
\tikzstyle{desicion} = [diamond, draw, text width=3em, text badly centered, inner sep=0pt]%, node distance=3cm]
\tikzstyle{block} = [rectangle, draw, text width=10em, text centered, rounded corners]%, minimum height=4em]
\tikzstyle{cloud} = [draw, ellipse, minimum height=2em]

\begin{tikzpicture}[descr/.style={fill=white,inner sep=2.5pt}]
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]{
\node [block] {A. Campos [1;14]}; & \\
\node [block] {B. Bineado [1;4]}; & \\
\node [cloud] {call \texttt{analisis\_campo}}; & \\
\node [block] {C. Modelos [1;2]}; & \\
\node [block] {D. Extinción [1;31]}; &  \node [block] {E. Fracción de binarias [1;2]}; \\
\node [cloud] {call \texttt{analisis\_modelo}}; & \\
\node [cloud] {call \texttt{analisis\_final}}; & \node [desicion] {\scriptsize{Fin E}}; \\
\node [desicion] {\scriptsize{Fin D}}; & \\
\node [desicion] {\scriptsize{Fin C}}; & \\
\node [desicion] {\scriptsize{Fin B}}; & \\
\node [desicion] {\scriptsize{Fin A}}; & \\
\node [block] {Stop}; & \\
 };
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\path [>=latex,->] (m-3-1) edge (m-4-1);
\path [>=latex,->] (m-4-1) edge (m-5-1);
\path [>=latex,->,dashed] (m-5-1) edge node[auto] {\scriptsize{MODEL}} (m-5-2);
\draw [>=latex,->] (m-5-2) |- (m-6-1);
\path [>=latex,->] (m-5-1) edge (m-6-1);
\path [>=latex,->] (m-6-1) edge (m-7-1);
\path [>=latex,->,dashed] (m-7-1) edge node[auto] {\scriptsize{MODEL}} (m-7-2);
\path [>=latex,->] (m-7-1) edge (m-8-1);
\path [>=latex,->,font=\scriptsize] (m-7-2) edge [bend right=60] node[descr] {No} (m-5-2);
\path [>=latex,->,font=\scriptsize] (m-8-1) edge [bend left=60] node[descr] {No} (m-5-1);
\path [>=latex,->,font=\scriptsize] (m-9-1) edge [bend left=60] node[descr] {No} (m-4-1);
\path [>=latex,->,font=\scriptsize] (m-10-1) edge [bend left=60] node[descr] {No} (m-2-1);
\path [>=latex,->,font=\scriptsize] (m-11-1) edge [bend left=60] node[descr] {No} (m-1-1);
\draw [>=latex,->,font=\scriptsize] (m-7-2) |- node[descr] {Sí} (m-8-1);
\path [>=latex,->,font=\scriptsize] (m-8-1) edge node[descr] {Sí} (m-9-1);
\path [>=latex,->,font=\scriptsize] (m-9-1) edge node[descr] {Sí} (m-10-1);
\path [>=latex,->,font=\scriptsize] (m-10-1) edge node[descr] {Sí} (m-11-1);
\path [>=latex,->,font=\scriptsize] (m-11-1) edge node[descr] {Sí} (m-12-1);
\end{tikzpicture}

\end{document}

以下是我通过该代码获得的结果:

在此处输入图片描述

答案1

除了使用edge,您还可以使用to操作(必须与 一起使用\draw,而不是\path)。这样您就可以非常精细地控制节点或坐标的连接方式。您可以使用 定义任意路径to path=<path definition>,其中(\tikztostart)(\tikztotarget)(\tikztonodes)保存路径的起点和终点以及您使用操作定义的节点to。如果您定义包含 的样式to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },则可以将参数传递给样式,然后 to 路径将绘制一条指定距离的水平线,将节点放置在该线上,然后绘制一条与目标正交的线。

我还更改了你的代码以使用语法\tikzset{<style name>/.style={<options>}}而不是过时的\tikzstyle命令。

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}

\begin{document}

% Define block styles
\tikzset{
    desicion/.style={
        diamond,
        draw,
        text width=3em,
        text badly centered,
        inner sep=0pt
    },
    block/.style={
        rectangle,
        draw,
        text width=10em,
        text centered,
        rounded corners
    },
    cloud/.style={
        draw,
        ellipse,
        minimum height=2em
    },
    descr/.style={
        fill=white,
        inner sep=2.5pt
    },
    connector/.style={
     -latex,
     font=\scriptsize
    },
    rectangle connector/.style={
        connector,
        to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
        pos=0.5
    },
    rectangle connector/.default=-2cm,
    straight connector/.style={
        connector,
        to path=--(\tikztotarget) \tikztonodes
    }
}

\begin{tikzpicture}
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]{
\node [block] {A. Campos [1;14]}; & \\
\node [block] {B. Bineado [1;4]}; & \\
\node [cloud] {call \texttt{analisis\_campo}}; & \\
\node [block] {C. Modelos [1;2]}; & \\
\node [block] {D. Extinción [1;31]}; &  \node [block] {E. Fracción de binarias [1;2]}; \\
\node [cloud] {call \texttt{analisis\_modelo}}; & \\
\node [cloud] {call \texttt{analisis\_final}}; & \node [desicion] {\scriptsize{Fin E}}; \\
\node [desicion] {\scriptsize{Fin D}}; & \\
\node [desicion] {\scriptsize{Fin C}}; & \\
\node [desicion] {\scriptsize{Fin B}}; & \\
\node [desicion] {\scriptsize{Fin A}}; & \\
\node [block] {Stop}; & \\
 };
\path [>=latex,->] (m-1-1) edge (m-2-1);
\path [>=latex,->] (m-2-1) edge (m-3-1);
\path [>=latex,->] (m-3-1) edge (m-4-1);
\path [>=latex,->] (m-4-1) edge (m-5-1);
\path [>=latex,->,dashed] (m-5-1) edge node[auto] {\scriptsize{MODEL}} (m-5-2);
\draw [>=latex,->] (m-5-2) |- (m-6-1);
\path [>=latex,->] (m-5-1) edge (m-6-1);
\path [>=latex,->] (m-6-1) edge (m-7-1);
\path [>=latex,->,dashed] (m-7-1) edge node[auto] {\scriptsize{MODEL}} (m-7-2);
\path [>=latex,->] (m-7-1) edge (m-8-1);
\draw [rectangle connector=2.5cm] (m-7-2) to node[descr] {No} (m-5-2);
\draw [rectangle connector=-3cm] (m-8-1) to  node[descr] {No} (m-5-1);
\draw [rectangle connector=-4cm,] (m-9-1) to node[descr] {No} (m-4-1);
\draw [rectangle connector=-5cm] (m-10-1) to  node[descr] {No} (m-2-1);
\draw [rectangle connector=-6cm] (m-11-1) to node[descr] {No} (m-1-1);
\draw [connector] (m-7-2) |- node[descr, pos=0.25] {Sí} (m-8-1);
\draw [straight connector] (m-8-1) to node[descr] {Sí} (m-9-1);
\draw [straight connector] (m-9-1) to node[descr] {Sí} (m-10-1);
\draw [straight connector] (m-10-1) to node [descr] {Sí} (m-11-1);
\draw [straight connector] (m-11-1) to node [descr] {Sí} (m-12-1) ;
\end{tikzpicture}

\end{document}

如果你使用的是tikzv3.0

对于 v3.0,语法略有改变;上述代码可以适用于

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning,chains}

\begin{document}

% Define block styles
\tikzset{
    desicion/.style={
        diamond,
        draw,
        text width=3em,
        text badly centered,
        inner sep=0pt
    },
    block/.style={
        rectangle,
        draw,
        text width=10em,
        text centered,
        rounded corners
    },
    cloud/.style={
        draw,
        ellipse,
        minimum height=2em
    },
    descr/.style={
        fill=white,
        inner sep=2.5pt
    },
    connector/.style={
        -latex,
        font=\scriptsize
    },
    rectangle connector/.style={
        connector,
        to path={(\tikztostart) -- ++(#1,0pt) \tikztonodes |- (\tikztotarget) },
        pos=0.5
    },
    rectangle connector/.default=-2cm,
    straight connector/.style={
        connector,
        to path=--(\tikztotarget) \tikztonodes
    }
}

\begin{tikzpicture}
    \matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, align=center, nodes={rectangle,draw, anchor=center} ]{
        |[block]| {A. Campos [1;14]}               &                                             \\
        |[block]| {B. Bineado [1;4]}               &                                             \\
        |[cloud]| {call \texttt{analisis\_campo}}  &                                             \\
        |[block]| {C. Modelos [1;2]}               &                                             \\
        |[block]| {D. Extinción [1;31]}            & |[block]| {E. Fracción de binarias [1;2]}   \\
        |[cloud]| {call \texttt{analisis\_modelo}} &                                             \\
        |[cloud]| {call \texttt{analisis\_final}}  & |[desicion]| {\scriptsize{Fin E}}           \\
        |[desicion]| {\scriptsize{Fin D}}          &                                             \\
        |[desicion]| {\scriptsize{Fin C}}          &                                             \\
        |[desicion]| {\scriptsize{Fin B}}          &                                             \\
        |[desicion]| {\scriptsize{Fin A}}          &                                             \\
        |[block]| {Stop}                           &                                             \\
    };
    \path [>=latex,->] (m-1-1) edge (m-2-1);
    \path [>=latex,->] (m-2-1) edge (m-3-1);
    \path [>=latex,->] (m-3-1) edge (m-4-1);
    \path [>=latex,->] (m-4-1) edge (m-5-1);
    \path [>=latex,->,dashed] (m-5-1) edge node[auto] {\scriptsize{MODEL}} (m-5-2);
    \draw [>=latex,->] (m-5-2) |- (m-6-1);
    \path [>=latex,->] (m-5-1) edge (m-6-1);
    \path [>=latex,->] (m-6-1) edge (m-7-1);
    \path [>=latex,->,dashed] (m-7-1) edge node[auto] {\scriptsize{MODEL}} (m-7-2);
    \path [>=latex,->] (m-7-1) edge (m-8-1);
    \draw [rectangle connector=2.5cm] (m-7-2) to node[descr] {No} (m-5-2);
    \draw [rectangle connector=-3cm] (m-8-1) to  node[descr] {No} (m-5-1);
    \draw [rectangle connector=-4cm,] (m-9-1) to node[descr] {No} (m-4-1);
    \draw [rectangle connector=-5cm] (m-10-1) to  node[descr] {No} (m-2-1);
    \draw [rectangle connector=-6cm] (m-11-1) to node[descr] {No} (m-1-1);
    \draw [connector] (m-7-2) |- node[descr, pos=0.25] {Sí} (m-8-1);
    \draw [straight connector] (m-8-1) to node[descr] {Sí} (m-9-1);
    \draw [straight connector] (m-9-1) to node[descr] {Sí} (m-10-1);
    \draw [straight connector] (m-10-1) to node [descr] {Sí} (m-11-1);
    \draw [straight connector] (m-11-1) to node [descr] {Sí} (m-12-1) ;
\end{tikzpicture}

\end{document}

答案2

Jake 的回答很好。我给出了另一种可能性

\draw [>=latex,->,font=\scriptsize] (m-8-1) -- +(-3,0) |-  node[pos=.25,descr] {No} (m-5-1);
\draw [>=latex,->,font=\scriptsize] (m-9-1) -- +(-4,0) |-  node[pos=.25,descr] {No} (m-4-1);
\draw [>=latex,->,font=\scriptsize] (m-10-1)-- +(-5,0) |-  node[pos=.25,descr] {No} (m-2-1);
\draw [>=latex,->,font=\scriptsize] (m-11-1)-- +(-6,0) |-  node[pos=.25,descr] {No} (m-1-1);

相关内容