带有自定义末端锚点的 Tikz 箭头

带有自定义末端锚点的 Tikz 箭头

我正在创建流程图Tikz,我想用箭头连接两个形状。问题是,箭头需要结束,而不是结束于中心,而是从左侧开始的 80% 左右。考虑以下最小示例:

\documentclass[a4paper, 12pt]{report} % a4paper option recommended
\usepackage{tikz}
\usepackage[latin1]{inputenc}
\usetikzlibrary{shapes,arrows}

\tikzstyle{start} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]

\tikzstyle{arrow} = [thick,->,>=stealth]


\tikzstyle{assignment} = [trapezium, trapezium left angle=80, trapezium right angle=100, minimum height=1cm, text centered, draw=black, fill=blue!30, text width=4.5cm]

\begin{document}


    \begin{center}
        \begin{tikzpicture}[node distance = 1.75cm]
            % Place nodes

            \node [start] (somedecision) {Yes/No?};

            \node [assignment, above of=somedecision,yshift=2cm, xshift=-2.25cm] (someblock) {Var $\gets$ \textit{something}};

            \node [block, below of = someblock, yshift=-2cm, xshift=-1.5cm] (someaction) {Do something};

            \draw [arrow] (somedecision.north) -- node {no} (someblock.south);

            \draw [arrow] (someblock) -- (someaction);

        \end{tikzpicture}
    \end{center}
\end{document}

决策框中的箭头指向上方框的底部中心,但我希望它只是向上(最短路线)。同样,我希望左箭头(从上方框到左侧框)从左侧开始,以便它可以向下(最短路线)到达指定框。

有什么方法可以做到这一点?我尝试寻找它,但似乎找不到。

谢谢。

答案1

这种连接的语法是\draw (nodeA.north) -- (nodeA|-nodeB.south);

% arara: pdflatex

\documentclass[a4paper, 12pt]{report} % a4paper option recommended
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\tikzset{%
    ,start/.style = {diamond, draw, fill=blue!20, text width=4.5em, text badly centered, inner sep=0pt}
    ,block/.style = {rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em}
    ,arrow/.style = {thick, -stealth}
    ,assignment/.style = {trapezium, trapezium left angle=80, trapezium right angle=100, minimum height=1cm, text centered, draw=black, fill=blue!30, text width=4.5cm}
}

\begin{document}    
    \begin{center}
        \begin{tikzpicture}[node distance = 3cm]
        \node [start] (somedecision) {Yes/No?};     
        \node [assignment, above left = of somedecision] (someblock) {Var $\gets$ \textit{something}};      
        \node [block, below left = 2.5cm of someblock] (someaction) {Do something};     
        \draw [arrow] (somedecision.north) -- node[fill=white]{no} (somedecision|-someblock.south);     
        \draw [arrow] (someblock) -- (someaction);      
        \end{tikzpicture}
    \end{center}
\end{document}

enter image description here

相关内容