Tikz:节点组的水平居中

发布于 2024-09-03 17:07:30 字数 1020 浏览 9 评论 0原文

我需要将图表的每一行与中心对齐。我正在尝试用 xshift 来做到这一点。这是代码:

    \begin{tikzpicture}[node distance=1.5cm, auto, text centered]
    \tikzstyle{every node}=[draw,ball];
    \begin{scope}[xshift=1.5cm]
        \node (A) {A};
        \node [right of=A] (B) {B};
        \node [right of=B] (C) {C};
        \node [right of=C] (D) {D};
    \end{scope}
    \begin{scope}[yshift=-1.5cm]
        \node (AB) {AB};
        \node [right of=AB] (AC) {AC};
        \node [right of=AC] (AD) {AD};
        \node [right of=AD] (BC) {BC};
        \node [right of=BC] (BD) {BD};
        \node [right of=BD] (CD) {CD};
    \end{scope}
    \begin{scope}[yshift=-3cm,node distance=2cm,xshift=1cm]
        \node (ABC) {ABC};
        \node [right of=ABC] (ABD) {ABD};
        \node [right of=ABD] (ACD) {ACD};
        \node [right of=ACD] (BCD) {BCD};
    \end{scope}
    \begin{scope}[xshift=4cm, yshift=-4.5cm, node distance=2cm]
        \node (ABCD) {ABCD};
    \end{scope}
\end{tikzpicture}

还有其他方法吗?不喜欢每次都改变 xshift 值。

I need to align each row of the graph to the center. I am trying to do it with xshift. Here the code:

    \begin{tikzpicture}[node distance=1.5cm, auto, text centered]
    \tikzstyle{every node}=[draw,ball];
    \begin{scope}[xshift=1.5cm]
        \node (A) {A};
        \node [right of=A] (B) {B};
        \node [right of=B] (C) {C};
        \node [right of=C] (D) {D};
    \end{scope}
    \begin{scope}[yshift=-1.5cm]
        \node (AB) {AB};
        \node [right of=AB] (AC) {AC};
        \node [right of=AC] (AD) {AD};
        \node [right of=AD] (BC) {BC};
        \node [right of=BC] (BD) {BD};
        \node [right of=BD] (CD) {CD};
    \end{scope}
    \begin{scope}[yshift=-3cm,node distance=2cm,xshift=1cm]
        \node (ABC) {ABC};
        \node [right of=ABC] (ABD) {ABD};
        \node [right of=ABD] (ACD) {ACD};
        \node [right of=ACD] (BCD) {BCD};
    \end{scope}
    \begin{scope}[xshift=4cm, yshift=-4.5cm, node distance=2cm]
        \node (ABCD) {ABCD};
    \end{scope}
\end{tikzpicture}

Is there any other way to do it? Do not like to change xshift values every time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢蛋碎的人ぎ生 2024-09-10 17:07:30

您可以将每一行设为自己的矩阵,从而使您可以有效地将一组节点分组为一个。

您的示例

\begin{tikzpicture}[auto]
    \begin{scope}[]
        \matrix[nodes={draw,ball}, column sep=1cm]{
            \node (A) {A}; &
            \node (B) {B}; &
            \node (C) {C}; &
            \node (D) {D}; \\
            };
    \end{scope}
    \begin{scope}[yshift=-1.5cm]
        \matrix[nodes={draw,ball}, column sep=1cm]{
            \node (AB) {AB}; &
            \node (AC) {AC}; &
            \node (AD) {AD}; &
            \node (BC) {BC}; &
            \node (BD) {BD}; &
            \node (CD) {CD}; \\
        };
     \end{scope}
     \begin{scope}[yshift=-3cm]
        \matrix[nodes={draw,ball}, column sep=1cm]{
            \node (ABC) {ABC}; &
            \node (ABD) {ABD}; &
            \node (ACD) {ACD}; &
            \node (BCD) {BCD}; \\
        };
    \end{scope}
    \begin{scope}[yshift=-4.5cm]
        \matrix[nodes={draw,ball}, column sep=1cm]{
            \node (ABCD) {ABCD}; \\
        };
    \end{scope}
\end{tikzpicture}

注意:请确保 \usetikzlibrary{matrix}

结果为

替代文本

我创造了自己的风格。

You can make each row its own matrix, allowing you to effectively group a set of nodes into one.

Your Example

\begin{tikzpicture}[auto]
    \begin{scope}[]
        \matrix[nodes={draw,ball}, column sep=1cm]{
            \node (A) {A}; &
            \node (B) {B}; &
            \node (C) {C}; &
            \node (D) {D}; \\
            };
    \end{scope}
    \begin{scope}[yshift=-1.5cm]
        \matrix[nodes={draw,ball}, column sep=1cm]{
            \node (AB) {AB}; &
            \node (AC) {AC}; &
            \node (AD) {AD}; &
            \node (BC) {BC}; &
            \node (BD) {BD}; &
            \node (CD) {CD}; \\
        };
     \end{scope}
     \begin{scope}[yshift=-3cm]
        \matrix[nodes={draw,ball}, column sep=1cm]{
            \node (ABC) {ABC}; &
            \node (ABD) {ABD}; &
            \node (ACD) {ACD}; &
            \node (BCD) {BCD}; \\
        };
    \end{scope}
    \begin{scope}[yshift=-4.5cm]
        \matrix[nodes={draw,ball}, column sep=1cm]{
            \node (ABCD) {ABCD}; \\
        };
    \end{scope}
\end{tikzpicture}

Note: be sure to \usetikzlibrary{matrix}

Results in

alt text

(I made up my own ball style.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文