gpt4 book ai didi

latex - 在 Tikz 节点之间自动居中标签

转载 作者:行者123 更新时间:2023-12-02 01:10:50 25 4
gpt4 key购买 nike

我是使用 latex 包 Tikz 的新手,我正在尝试编写 Tableau。我的问题是在 sibling 之间创造足够的空间,以便我可以在中心放置一个标签。这就是我所做的。我想尽可能避免手动间距,所以我正在寻找一个通用的解决方案。

 \begin{tikzpicture}[auto, node distance=1.3cm]


\node (A) {$X^1$};
\node (B) [below of=A] {$X^2$};
\node (C) [below of=B] {$X^3$};
\node (D) [below of=C] {$X^4$};
\node (E) [below of=D] {$X^5$};
\node (F) [label={[label distance=-1cm] \color{green}{Complete}}, below left of=E,left=1cm] {$X^6$};
\node (G) [below right of=E, right=1cm] {$X^7$};
\node (H) [below left of=G,left=1cm] {$X^8$};
\node (I) [label={[label distance=-1cm] \color{red}{Closed}}, below right of=G, right=1cm] {$X^9$};
\node (L) [label={[label distance=-1cm] \color{red}{Closed}}, below of=H] {$X^{10}$};


\path (A) edge (B);
\path (B) edge (C);
\path (C) edge (D);
\path (D) edge (E);
\path (E) edge node [below=0.3cm, right=0.4cm]{PB-Rule} (F)
edge (G);
\path (G) edge node [below=0.3cm, right=0.4cm] {PB-Rule} (H)
edge (I);
\path (H) edge node {E-Rule} (L);

\end{tikzpicture}

有什么建议吗?

最佳答案

要将标签放置在 sibling 之间,您可以使用 !0.5!句法:

\begin{tikzpicture}[auto, node distance=1.3cm]
\node (A) {$X^1$};
\node (B) [below of=A] {$X^2$};
\node (C) [below of=B] {$X^3$};
\node (D) [below of=C] {$X^4$};
\node (E) [below of=D] {$X^5$};
\node (F) [label={[label distance=-1cm] \color{green}{Complete}}, below left of=E,left=1cm] {$X^6$};
\node (G) [below right of=E, right=1cm] {$X^7$};
\node (H) [below left of=G,left=1cm] {$X^8$};
\node (I) [label={[label distance=-1cm] \color{red}{Closed}}, below right of=G, right=1cm] {$X^9$};
\node (L) [label={[label distance=-1cm] \color{red}{Closed}}, below of=H] {$X^{10}$};

\node (label1) at ($(F)!0.5!(G)$) {PB-Rule};
\node (label2) at ($(H)!0.5!(I)$) {PB-Rule};

\path (A) edge (B);
\path (B) edge (C);
\path (C) edge (D);
\path (D) edge (E);
\path (E) edge (F);
\path (E) edge (G);
\path (G) edge (H);
\path (G) edge (I);
\path (H) edge node {E-Rule} (L);
\end{tikzpicture}

注意:您将需要该语法的 calc tikz 库。

enter image description here

关于latex - 在 Tikz 节点之间自动居中标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45242862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com