tikzpicture 从一个节点到另一个节点的垂直线

tikzpicture 从一个节点到另一个节点的垂直线

假设有两个节点 A 和 B,B 位于 A 下方。这两个节点的宽度不同。将 A.south 连接到 B.north 会产生一条斜线。我想知道如何将 A.south 连接到 B,并使连接垂直。我不想将 A.south 连接到 B.8,这样会产生一条直线,但是当 B 的宽度发生变化时,连接将不再是直线。

MWE 如下:

\documentclass[10pt]{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\tikzset{font=\Large,
every node/.style=
    {minimum height=8mm,
    draw=blue,
    very thick,
    },
data/.style = {draw, node distance=3cm}
    }

The line from A to B is vertical in the following example.


\begin{tikzpicture}
\node (a) {A};
\node[below right=of a] (c) {C};
\node[left=of c] (B) {BBBBBBBBBBBBBBBBBB};
\draw[->][very thick](a.south) -- (B.8);
\end{tikzpicture}

\medskip 

The line from A to B is not vertical in the following example.

\medskip

\begin{tikzpicture}
\node (a) {A};
\node[below right=of a] (c) {C};
\node[left=of c] (B) {BBBBBBBBBBBBBBBBBBBBB};
\draw[->][very thick](a.south) -- (B.8);
\end{tikzpicture}

\end{document}

答案1

您可以使用垂直坐标系;例如

\draw (A.south) -- (A.south|-B.north);

将从 到 绘制一条线A.south,该点的x-坐标与相同,且-坐标A.south与 相同。举个小例子:yB.north

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node[draw] at (0,0) (A) {short text};
\node[draw] at (0.2,-2) (B) {Some longer text};
\draw[green] (A.south) -- (B.north);
\draw[red] (A.south) -- (A.south|-B.north);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容