latex - Tikz:节点组的水平居中

标签 latex tikz centering pgf

我需要将图表的每一行与中心对齐。我正在尝试用 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 值。

最佳答案

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

你的例子

\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}

结果

alt text

(我创造了自己的风格。)

关于latex - Tikz:节点组的水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2940923/

相关文章:

python - 更改默认的seaborn热图

latex - 在带有边缘节点tikz的箭头(不位于下方/上方)之间插入标签

html - 中心 div 宽度取决于内容

html - 在页面调整大小时动态居中 block ?

latex - 评估一个函数并分配给一个常量以用作 Tikz/pgfplots 中的刻度标记

python - pybtex 是否支持 .bib 文件中的重音/特殊字符?

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

html - 两个 div 内的文本水平居中

svg - 如何在 beamer latex 上添加 svg 文件扩展名?

latex - 在 Latex Tikz 库中的节点文本中输入换行符