TikZ 选择路径的起点/终点

TikZ 选择路径的起点/终点

考虑以下代码:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{block} = [rectangle, draw, node distance=3cm,
    text width=5em, text centered, minimum height=4em]
\tikzstyle{line} = [draw, -latex']

\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [block] (A) {A};
    \node [block, right of=A] (B) {B}; 
    \node [block, below of=A] (C) {long text long text long text long
      text long text long text long text };
    % Draw edges
    \path [line] (A) -- (C);
    \path [line] (B) -- (C);
\end{tikzpicture}
\end{document}

输出如下:

在此处输入图片描述

我怎样才能让 A 和 B 的两个箭头位于长文本块的同一侧?

因为它是 MWE,所以我想尽可能保留相同的代码(所以如果可以的话就不用宏)和两条直线。

答案1

您可以将锚点用作节点(如果需要,还可以使用移位);例如,<name>.north<name>.<angle>,或类似

($(<name>.north)!0.5!(<name>.north east)$);

(需要calc图书馆)。

以下示例展示了其中一些可能性:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc}

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{block} = [rectangle, draw, node distance=3cm,
    text width=5em, text centered, minimum height=4em]
\tikzstyle{line} = [draw, -latex']

\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [block] (A) {A};
    \node [block, right of=A] (B) {B}; 
    \node [block, below of=A] (C) {long text long text long text long
      text long text long text long text };
    % Draw edges
    \path [line] (A) -- (C);
    \path [line] ([yshift=12pt]B.south west) -- (C.90);
    \path [line,blue] (B) -- ($(C.north)!0.5!(C.north east)$);
    \path [line,red] (B.south west) -- (C.62);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容