相对于多个节点定位节点

相对于多个节点定位节点

我想放置一个相对于多个节点的节点。在此邮政calc其中一个答案中建议使用该库。在下图中,居中节点 (E) 并未位于所有节点的正中心。

在此处输入图片描述

我可以通过确定每个节点的精确位置来解决这个问题,但我想利用positioning包来自动执行它。有没有办法自动定位一个节点相对于多个节点的位置?(我的意思是像below=of right=of ... etc

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows, decorations.pathmorphing, backgrounds, positioning,fit,petri}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
    [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        place/.style={circle,draw=blue!50,fill=blue!20,thick,
                      inner sep=0pt,minimum size=6mm}
    ]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     \node[place] (A)               {A};
     \node[place] (B) [right=of A]  {B};
     \node[place] (C) [below=of B]  {C};
     \node[place] (D) [left=of  C]  {D};
     \coordinate (Middle) at ($(A)!0.5!(B)$);
     \node[place] (E) [below of=Middle] {E};

\end{tikzpicture}
\end{document}

答案1

您可以使用baricentric cs来完成此类作业。有关详细信息,请参阅pgfmanual,第 133 页,第 13.2.2 节。

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows, decorations.pathmorphing, backgrounds, positioning,fit,petri}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}
    [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        place/.style={circle,draw=blue!50,fill=blue!20,thick,
                      inner sep=0pt,minimum size=6mm}
    ]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     \node[place] (A)               {A};
     \node[place] (B) [right=of A]  {B};
     \node[place] (C) [below=of B]  {C};
     \node[place] (D) [left=of  C]  {D};
     \coordinate (Middle) at ($(A)!0.5!(B)$);
     \node[place] (E)  at (barycentric cs:A=0.5,B=0.5,C=0.5,D=0.5)  {E};

\end{tikzpicture}
\end{document}

在此处输入图片描述

您可以调整它们0.5来改变位置。

答案2

重心坐标系Harish 的回答提供了一个相当通用的方法;然而,在这个具体例子中,你可以使用calc库(已经加载到你的代码中),只需说

\node[place] (E) at ( $ (A)!0.5!(C) $ ) {E};

完整代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tikzpicture}[
  place/.style={circle,draw=blue!50,fill=blue!20,thick,inner sep=0pt,minimum size=6mm}
]
\node[place] (A) {A};
\node[place] (B) [right=of A] {B};
\node[place] (C) [below=of B] {C};
\node[place] (D) [left=of  C] {D};
\node[place] (E) at ( $ (A)!0.5!(C) $ ) {E};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容