如何计算块的 y 坐标以将其放置在另外两个块之间?

如何计算块的 y 坐标以将其放置在另外两个块之间?

假设我们有一个包含两个分支的流程图:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{calc,shapes, positioning}
\begin{document}
\def\len{1cm}
\begin{tikzpicture}[node distance = \len, auto]
\tikzset{
    line/.style = {draw},
    block/.style = {rectangle, draw, text centered, minimum height=2em},
    question/.style = {shape=chamfered rectangle, chamfered rectangle xsep=2cm, draw},
}
%branch 1
\node [question] (1-1) {1-1};
\node [block, below = of 1-1] (1-2) {1-2};
\path [line] (1-1) -- (1-2);
\node [block, below = of 1-2] (1-3) {1-3};
\path [line] (1-2) -- (1-3);
\node [coordinate, below = of 1-3] (1-4) {};
\path [line] (1-3) -- (1-4);
\node [block, below = of 1-4] (1-5) {1-5};
\path [line] (1-4) -- (1-5);
%branch 1
\node [block, right = of 1-2] (2-1) {2-1};
\path [line] (1-1) -| (2-1);
\path [line] (2-1) |- (1-4);
\end{tikzpicture}
\end{document}

在此处输入图片描述

分支 2 只有 1 个块。而分支 1 可以有多个块,但不能超过 1 个(为简单起见,我使用了 2 个)。

我如何设置节点 (2-1.y) 坐标 = (1-1.south.y) + ((1-1.south.y) - (1-4.y))?

注意:图像上未显示 1-4。

答案1

您可以通过计算坐标来继续,但也可以使用路径来解决这个问题:

\path (1-1) -- node[block,xshift=\len](2-1){2-1} (1-4);
\path [line] (1-1) -| (2-1);
\path [line] (2-1) |- (1-4);

(1-1)在这里,您在和(1-4)(您希望垂直居中的两个节点)之间追踪一条路径,(2-1)并在中间但向右移动,从而创建节点(2-1)

相关内容